Skip to content

Instantly share code, notes, and snippets.

@heavenshell
Created July 23, 2014 15:24
Show Gist options
  • Save heavenshell/e9439ca75c4251721f9f to your computer and use it in GitHub Desktop.
Save heavenshell/e9439ca75c4251721f9f to your computer and use it in GitHub Desktop.
var env = process.env.NODE_ENV || 'dev';
var winston = require('winston');
winston.setLevels(winston.config.syslog.levels)
if (env !== 'dev') {
winston.remove(winston.transports.Console);
}
var customColors = {
trace: 'white',
debug: 'green',
info: 'green',
warn: 'yellow',
crit: 'red',
fatal: 'red'
};
var logger = new (winston.Logger)({
colors: customColors,
levels: {
trace: 0,
debug: 1,
info: 2,
warn: 3,
crit: 4,
fatal: 5
},
transports: [
// Console.
new (winston.transports.Console)({
colorize: true,
timestamp: true
}),
// File.
new (winston.transports.File)({
filename: './logs/node.log',
level: 'info',
timestamp: true,
json: false,
maxsize: 100000,
maxFiles: 5,
})
]
});
winston.addColors(customColors);
module.exports = logger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment