Winston: File Transport maxsize is not working as expect

Created on 24 Nov 2015  路  7Comments  路  Source: winstonjs/winston

Hi All,

I find that when I define the file transport with setting as followed

const logger = new (winston.Logger)({
    transports: [
        new (winston.transports.File)({
            filename: config['log_file_name'],
            dirname: '/data/tmp/',
            //maxsize: 1000 * 1000 * 1024, // 1Gb
            maxsize: 102400, // 100 kb
            maxFiles: 1000,
            timestamp: function() {
                return Date.now()/1000|0;
            }
        })
    ],
    exitOnError: false
})

then, the final log size will be 4 times than the maxsize.

404K    rcv.log
400K    rcv1.log
240K    rcv2.log

According to the documentation, this result is not expected.

Thanks

winston-file

Most helpful comment

I use the following code for transport initialization:

winston.add(winston.transports.File, {
  name: 'errors',
  filename: 'logs/errors.log',
  level: 'error',
  maxsize: 10,
});

And then:

server.listen(server.get('port'), () => {
  winston.info(`The server is running at http://localhost:${server.get('port')}/`);
  winston.error(new Error('asdsad'));
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
});

Expected result:

several files, each file as small as possible.

Actual result:

one big file with all messages

All 7 comments

I am facing same issue winston 2.2.1. It is also writing in last 2-3 rotated log files. Is there any fix for it?

I use the following code for transport initialization:

winston.add(winston.transports.File, {
  name: 'errors',
  filename: 'logs/errors.log',
  level: 'error',
  maxsize: 10,
});

And then:

server.listen(server.get('port'), () => {
  winston.info(`The server is running at http://localhost:${server.get('port')}/`);
  winston.error(new Error('asdsad'));
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
  winston.error('cvxcvxcvcxvxcvxcvxcvxc');
});

Expected result:

several files, each file as small as possible.

Actual result:

one big file with all messages

I think I have the same issue.

My transport initialization:

let logger = new (winston.Logger)({
            transports: [
                new (winston.transports.File)({
                    level: 'info',
                    name: 'file.info',
                    timestamp: false,
                    meta: false,
                    json: false,
                    showLevel: false,
                    tailable: true,
                    filename: path.join(/path/to/folder, filename),
                    maxFiles: 10,
                    maxsize: 1048576
                })
            ]
        });

if then I try to log as follows

for (let i = 0; i < 10000; i++) {
            logger.info('asdasd');
            logger.info('asdasd');
            logger.info('asdasd');
            logger.info('asdasd');
            logger.info('asdasd');
}

the logfile will become bigger than the 1mb (ie. 1048576 bytes) maxsize option instead of splitting the log into multiple files (as the maxFiles option set to 10 should do).

My setup:
winston: 2.3.0
node: 6.9.1
platform: Ubuntu 14.04

Any idea?

I think that the issue #908 is also related to this one

Any update on this? Is there a workaround?

Same here. Any update on this issue?

Hey, I'm working on triaging issues -- any idea if this behavior/issue is still happening with the latest winston (3.1.0 or master)? Work on 2.x has ceased, and the File transport has gotten some big rewrites in 3.x that should solve some issues like these.

Was this page helpful?
0 / 5 - 0 ratings