Multiple log files with Winston?

后端 未结 5 1480
故里飘歌
故里飘歌 2020-12-14 09:36

We\'d like to use Winston for our logging in Node.js. But, we can\'t figure out how to have two log files: one for just errors, and one for everything else.

Doing th

5条回答
  •  佛祖请我去吃肉
    2020-12-14 10:03

    You just need to give the transport a custom name property so you don't have a collision:

    const logger = new (winston.Logger)({
      transports: [
        new (winston.transports.Console)(),
        new (winston.transports.File)({ name: 'text', filename: logFile, json: false }),
        new (winston.transports.File)({ name: 'json', filename: logFileJson })
      ]
    });
    

    You can read more about multiple transports in the docs: https://github.com/winstonjs/winston#multiple-transports-of-the-same-type

提交回复
热议问题