winston에서는 로그 파일 관리를 위해 다음과 같은 설정을 제공한다.

  • File Transport Options
    • maxsize: Max size in bytes of the logfile, if the size is exceeded then a new file is created, a counter will become a suffix of the log file.
      • 로그파일의 최대 크기를 지정가능하고, 해당 크기를 넘을 경우 새로운 로그파일을 생성
        • ex) error.log, error1.log, error2.log
    • maxFiles: Limit the number of files created when the size of the logfile is exceeded.
      • 생성되는 로그 파일의 갯수를 지정가능하고, maxFiles 갯수를 넘어갈경우 가장 오래된 파일을 삭제하고 새로 생성
    • zippedArchive: If true, all log files but the current one will be zipped.
      • 로그파일을 zip 파일로 유지
  • 예제
    • 로그파일을 최대 100MB x 5 개로 유지
    • var fileAppender = new winston.transports.File({
          timestamp: _timestamp,
          formatter: _customFormatter,
          json: false,
          filename: 'filelog.log',
          maxsize: 104857600, // 100 MB = 1024 * 1024 * 100 = 104857600 Bytes
          maxFiles: 5
      });
      
  • winston-daily-rotate-file
    • Daily로 로그를 생성하고 싶을 경우 winston-daily-rotate-file 모듈을 사용하면 된다.


Posted by leechwin
,