$ npm install winston-daily-rotate-file
A transport for winston which logs to a rotating file. Logs can be rotated based on a date, size limit, and old logs can be removed based on count or elapsed days.
Starting with version 2.0.0, the transport has been refactored to leverage the the file-stream-rotator module. Some of the options in the 1.x versions of the transport have changed. Please review the options below to identify any changes needed.
npm install winston-daily-rotate-file
The DailyRotateFile transport can rotate files by minute, hour, day, month, year or weekday. In addition to the options accepted by the logger, winston-daily-rotate-file also accepts the following options:
%DATE% placeholder which will include the formatted datePattern at that point in the filename. (default: 'winston.log.%DATE%) var winston = require('winston');
require('winston-daily-rotate-file');
var transport = new (winston.transports.DailyRotateFile)({
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport.on('rotate', function(oldFilename, newFilename) {
// do something fun
});
var logger = new (winston.Logger)({
transports: [
transport
]
});
logger.info('Hello World!');
You can listen for the rotate custom event. The rotate event will pass two parameters to the callback (oldFilename, newFilename).
MIT
© 2010 - cnpmjs.org x YWFE | Home | YWFE