How to use Winston in several modules?

前端 未结 11 1571
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 23:40

I have several modules - let\'s say server.js, module1.js,...,moduleN.js.

I would like define the log file in my server.js:

winston.add(winston.trans         


        
11条回答
  •  别那么骄傲
    2020-12-23 00:19

    I am working on Winston 3.0.0 right now. And it seems the way to configure the default logger has changed a little bit. The way that works for me is folloing:

    log.js// the setting for global logger

    const winston= require('winston');
    
    winston.configure({
      level:"debug",
      format: winston.format.combine(
        winston.format.colorize(),
        winston.format.simple()
      ),
      transports: [
        new winston.transports.Console()
      ]
    });
    

    The other part is the same. In the beginning of you application, require('log.js'), and also require ('winston'), While in all other files, simply require('winston')

    .

提交回复
热议问题