Search code examples
node.jswinstonnosql

Winston logger different file for different date


Does winston provide a way to write logs to different file when the date is changed?

e.g. errorLogs_10_04_2016.log, errorLogs_11_04_2016.log, errorLogs_12_04_2016.log

I need to export these logs, provide admin a way to export logs to a specific date.

Update: As suggested by krakig, I tried using DailyRotateFile transport.

var winston = require('winston');

var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.DailyRotateFile)({

            filename: 'logs.log',
            datePattern:'_dd-MM-yyyy'

        })
    ]
});

But I'm getting winston.transports.DailyRotateFile is not a function error.

My winston version is 2.2.0


Solution

  • The feature was added a while ago :

     winston.add(winston.transports.DailyRotateFile, {
          filename: './logs/my.log',
          datePattern: '.dd-MM-yyyy'
     });
    

    EDIT :

    I didn't mention it, but the package is independant. You have to get it from npm :

    winston.transports.DailyRotateFile = require('winston-daily-rotate-file');