Skip to content

Instantly share code, notes, and snippets.

@garth
Created May 1, 2012 19:36
Show Gist options
  • Save garth/2570757 to your computer and use it in GitHub Desktop.
Save garth/2570757 to your computer and use it in GitHub Desktop.
Wasted quite a bit of time today trying to get flatiron winston configured with custom levels and colors, so here's a working sample.
var winston = require('winston')
require('winston-mongodb')
// prepare some custom log levels
var customLevels = {
levels: {
debug: 0,
info: 1,
warning: 2,
error: 3
},
colors: {
debug: 'cyan',
info: 'green',
warning: 'yellow',
error: 'red'
}
}
// create the logger
var logger = module.exports = new (winston.Logger)({
level: 'debug',
levels: customLevels.levels,
handleExceptions: true,
//colors: customLevels.colors,
transports: [
// setup console logging
new (winston.transports.Console)({
level: 'debug',
levels: customLevels.levels,
handleExceptions: true,
colorize: true
}),
// setup logging to mongodb
new (winston.transports.MongoDB)({
host: 'localhost',
db: 'logDb',
collection: 'log',
level: 'info',
levels: customLevels.levels,
handleExceptions: true
})
]
})
// set the coloring
winston.addColors(customLevels.colors)
@craiggoldstone
Copy link

Wow, I wish I had found this gist about 4 hours ago. Thanks a lot for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment