简体   繁体   中英

How to log JSON to console and get cloudwatch logs pick up correct metadata?

winston.info('Hello again distributed logs', { app: 'test', sid: 1 })
pino.info('Hello again distributed logs', { app: 'test', sid: 1 })

Output:

{"app":"test","sid":1,"level":"info","message":"Hello again distributed logs","timestamp":"2017-02-16T03:34:06.186Z"}
{"pid":4269,"hostname":"Macchiato.local","level":30,"time":1487216046197,"msg":"Hello again distributed logs {\"app\":\"test\",\"sid\":1}","v":1}

I have fluentd daemon to pickup container stdout and ship it to cloudwatch.

In the example above, cloudwatchlogs can detect the metadata correctly from pino and I will be able to query the log like this

{$.app = "test"}

However, winston console is not working like that and everything got push to log attribute.

Does anyone know how to fix this. I'm using winston console with json: true and stringify: true

Turn out it's not an issue with winston .

I use pm2 to run node and i need to pass --raw arg to it to get raw log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM