Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winston js. My log files aren't rotating after exceeding maxsize

I have the following winston configuration:

'use strict'

import winston from 'winston'
import config from '../../config/environment'

export default winston.createLogger({
  level: 'info',
  format: winston.format.printf(info => info.message),
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({
      filename: `${config.logsPath}/express.error.log`,
      maxsize: 300,
      level: 'error'
    }),
    new winston.transports.File({
      filename: `${config.logsPath}/express.log`,
      maxsize: 300
    })]
})

None of this files are rotating after they reach the 300 bytes threshold.

like image 927
Francisco Farías Avatar asked Oct 12 '17 13:10

Francisco Farías


1 Answers

You are using the version 3.0.0 release candidate which has a bug in its File transport. Basically, once over the maxsize threshold, internal self.filename variable was not being updated so _createStream would re-open the append stream to the existing file and continue writing to it. It works the first time around because self.filename is set when initializing from options.

I've submitted a PR which fixes the issue. Alternatively, you can revert to 2.4.0 where this isn't an issue.

like image 150
Unglückspilz Avatar answered Oct 23 '22 04:10

Unglückspilz