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

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

    On "winston": "^3.2.1"

    This is works great for me

    const {createLogger, format} = require('winston');
    
    // instantiate a new Winston Logger with the settings defined above
    var logger = createLogger({
    
        format: format.combine(
          format.timestamp(),
          // format.timestamp({format:'MM/DD/YYYY hh:mm:ss.SSS'}),
          format.json(),
          format.printf(info => {
            return `${info.timestamp} [${info.level}] : ${info.message}`;
          })
      ),
      transports: [
        new winston.transports.File(options.file),
        new winston.transports.Console(options.console)
      ],
      exitOnError: false, // do not exit on handled exceptions
    });
    

提交回复
热议问题