Created
November 7, 2013 13:51
-
-
Save rtgibbons/7354879 to your computer and use it in GitHub Desktop.
Logger Library with winston
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 app = require(process.cwd() + '/app'); | |
var winston = require('winston'); | |
var _ = require('lodash'); | |
// Set up logger | |
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: [ | |
new(winston.transports.Console)({ | |
level: app.settings.logLevel, | |
colorize: true, | |
timestamp: true | |
}) | |
// new (winston.transports.File)({ filename: 'somefile.log' }) | |
] | |
}); | |
winston.addColors(customColors); | |
// Extend logger object to properly log 'Error' types | |
var origLog = logger.log; | |
logger.log = function (level, msg) { | |
var objType = Object.prototype.toString.call(msg); | |
if (objType === '[object Error]') { | |
origLog.call(logger, level, msg.toString()); | |
} else { | |
origLog.call(logger, level, msg); | |
} | |
}; | |
/* LOGGER EXAMPLES | |
app.logger.trace('testing'); | |
app.logger.debug('testing'); | |
app.logger.info('testing'); | |
app.logger.warn('testing'); | |
app.logger.crit('testing'); | |
app.logger.fatal('testing'); | |
*/ | |
module.exports = logger; |
How to move the monkey-patch of the log function to a proper transform property, this might come in handy: winstonjs/winston#1427 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have fixed everything . check here
https://gist.github.com/vikas5914/cf568748ac89446e19ecd5e2e6900443