koa2-winston icon indicating copy to clipboard operation
koa2-winston copied to clipboard

How to log a json body?

Open jcyh0120 opened this issue 6 years ago • 2 comments

The document showing custom config didn't work.

transports: new winston.transports.Console({ json: true, stringify: true }),

Seems that the config is not being pickup.

jcyh0120 avatar Jan 28 '19 08:01 jcyh0120

Sorry about that.

Config in the readme it work for winston@2.

Documents for winston@3, link down here.

BTW, if you use default transport, it would log in json string.

yidinghan avatar Jan 28 '19 08:01 yidinghan

@yidinghan Thanks for reply. This is by far the best logger suits the logging needs. I would like to log the json body of req and res. This is my configs.

app.use(logger({
  reqSelect: ['body'],
  resSelect: ['body']
}))

This is the console result I got

"body":{"user":"[object Object]"}}

is it possible to print the whole body to a json string?

jcyh0120 avatar Jan 28 '19 10:01 jcyh0120