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

前端 未结 5 980
刺人心
刺人心 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:27

    "winston": "^3.0.0"

    function createAppLogger() {
      const { combine, timestamp, printf, colorize } = format;
    
      return createLogger({
        level: 'info',
        format: combine(
          colorize(),
          timestamp(),
          printf(info => {
            return `${info.timestamp} [${info.level}] : ${JSON.stringify(info.message)}`;
          })
        ),
        transports: [new transports.Console()]
      });
    }
    

    Output:

    2018-08-11T13:13:37.554Z [info] : {"data":{"hello":"Hello, World"}}

提交回复
热议问题