컴퓨터 공학/JavaScript

[단순코드] Node.js 로거 모듈 winston/winston-daily-rotate-file 초기화

혼새미로 2019. 4. 6. 22:42
반응형
logger.prototype.init = function(){
  if(this.writer != null){
    return;
  }
 
  this.writer = winston.createLogger({
    transports: [
      new (winstonDaily)({
        name: 'info-file',
        filename: path.join(utils.LOG_PATH, './server_%DATE%.log'),
        datePattern: 'YYYY-MM-DD',
        colorize: false,
        maxsize: 50000000,
        maxFiles: 1000,
        level: 'info',
        showLevel: true,
        json: false,
        timestamp: time_stamp_format,
        format: winston.format.printf(
          info => `${time_stamp_format()} [${info.level.toUpperCase()}] - ${info.message}`
        )
      }),
      new (winston.transports.Console)({
        name: 'debug-console',
        colorize: true,
        level: 'debug',
        showLevel: true,
        json: false,
        timestamp: time_stamp_format,
        format: winston.format.printf(
          info => `${time_stamp_format()} [${info.level.toUpperCase()}] - ${info.message}`
        )
      })
    ]
  })
}

 

반응형