I use Winston for my backend logging I cannot log the object without using JSON.stringify
which is annoying
logger.debug(`Register ${JSON.stringify(
My solution was to use this kind of formatter:
const { format } = winston
const consoleFormat = format.combine(
format.prettyPrint(),
format.splat(),
format.printf((info) => {
if (typeof info.message === 'object') {
info.message = JSON.stringify(info.message, null, 3)
}
return info.message
})
)
now all those options works as expected:
logger.info('plain text')
logger.info('plain text with object %o', { a:1, b: 2} )
logger.info({ a:1, b: 2 })