-
Notifications
You must be signed in to change notification settings - Fork 97
Open
Description
The vision
Context
Certain types of log messages show up as [object Object]
e.g.
info: [object Object] {"timestamp":"2025-12-24T17:23:23.442Z"}
info: applied 1 migrations. {"event":"up","timestamp":"2025-12-24T17:23:23.443Z"}
Proposed Solution
Simple formatter with object printing.
import { format } from "winston"
import { has } from "lodash"
import { MESSAGE } from "triple-beam"
import stringify from "safe-stable-stringify"
import { type TransformableInfo } from "logform"
/**
* Winston's (Logform's) simple formatter, but stringifies object messages instead of producing "[object Object]".
*
* See https://github.com/winstonjs/logform/blob/18795bc185d5eb485fb0289d08c1e220a6d3e44c/simple.js
*/
export const simpleWithObjectHandling = format((info: TransformableInfo) => {
const stringifiedRest = stringify(
Object.assign({}, info, {
level: undefined,
message: undefined,
splat: undefined,
})
)
let message = info.message
if (typeof info.message === "object" && `${message}` === "[object Object]") {
message = stringify(info.message)
}
let padding = ""
if (has(info, "padding") && has(info.padding, info.level)) {
padding = info.padding[info.level]
}
if (stringifiedRest !== "{}") {
info[MESSAGE] = `${info.level}:${padding} ${message} ${stringifiedRest}`
} else {
info[MESSAGE] = `${info.level}:${padding} ${message}`
}
return info
})
export default simpleWithObjectHandlingProduces
info: {"durationSeconds":0.235,"event":"migrated","name":"2025.12.04T08.57.45.create-building-expense-categories-table.ts"} {"timestamp":"2025-12-24T17:24:31.156Z"}
info: applied 1 migrations. {"event":"up","timestamp":"2025-12-24T17:24:31.156Z"}
Use case
icefoganalytics/elcc-data-management@1018a12
🔎 Search Terms
simple; [object Object]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels