How do I change my node winston JSON output to be single line

前端 未结 5 979
刺人心
刺人心 2021-02-04 01:54

When I create a nodejs winston console logger and set json:true, it always output JSON logs in multiline format. If I pipe these to a file and try to grep that file

5条回答
  •  不知归路
    2021-02-04 02:45

    The winston transports provide a way to override the stringify method, so by modifying the config above I got single line JSON output.

    New config:

    winston = require('winston')
    logger = new (winston.Logger)({
      transports: [
        new winston.transports.Console({
         json: true,
         stringify: (obj) => JSON.stringify(obj)
        })
      ]
    })
    

提交回复
热议问题