Created
July 23, 2014 15:24
-
-
Save heavenshell/e9439ca75c4251721f9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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