Skip to content

Instantly share code, notes, and snippets.

@pbaio
Last active March 26, 2019 03:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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