Skip to content

Instantly share code, notes, and snippets.

@joshelson joshelson/logger.js forked from rtgibbons/logger.js
Last active Aug 29, 2017

Embed
What would you like to do?
Logger Library with winston
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: {
fatal: 0,
crit: 1,
warn: 2,
info: 3,
debug: 4,
trace: 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.