Skip to content

Instantly share code, notes, and snippets.

@pbaio
Last active March 26, 2019 03:23
Show Gist options
  • Save pbaio/ac934a06b91b99be6526 to your computer and use it in GitHub Desktop.
Save pbaio/ac934a06b91b99be6526 to your computer and use it in GitHub Desktop.
Winston Transports setup for Daily Rotation and separate files per log level
'use strict';
var winston = require('winston');
var DailyRotateFile = require('winston-daily-rotate-file');
winston.emitErrs = true;
var logger = new winston.Logger( {
transports: [
new winston.transports.Console({
level: 'debug',
handleExceptions: true,
json: true,
colorize: true,
humanReadableUnhandledException: true
}),
new DailyRotateFile({
name: 'log.info',
level: 'info',
datePattern: 'yyyy-MM-dd',
filename: './logs/info.log',
handleExceptions: false,
json: true,
maxsize: 5242880,
maxFiles: 10,
colorize: true
}),
new DailyRotateFile({
name: 'log.warn',
level: 'warn',
filename: './logs/warn.log',
handleExceptions: false,
json: true,
maxsize: 5242880,
maxFiles: 10,
colorize: true,
datePattern: 'yyyy-MM-dd'
}),
new DailyRotateFile({
name: 'log.error',
level: 'error',
filename: './logs/error.log',
handleExceptions: true,
humanReadableUnhandledException: true,
json: true,
maxsize: 5242880,
maxFiles: 10,
colorize: true,
datePattern: 'yyyy-MM-dd'
})
],
exitOnError: false
});
module.exports = logger;
module.exports.stream = {
write: function (message) {
logger.info(message);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment