Created
July 24, 2014 16:15
-
-
Save tomgco/d9c5bfa898cd64754891 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 logger = require('logger')(module); | |
logger.info('Om nom nom'); | |
// Same output |
This file contains hidden or 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 Module = require('module'); | |
module.exports = function logger(module) { | |
function log(level) { | |
return function () { | |
var args = [(new Date()).toJSON(), level]; | |
if (module instanceof Module) { | |
args.push(module.id); | |
} | |
args.push.apply(args, Array.prototype.slice.call(arguments)); | |
console.log.apply(console, args); | |
}; | |
} | |
var levels = [ | |
'trace', | |
'debug', | |
'info', | |
'warn', | |
'error', | |
'fatal' | |
]; | |
var methods = {}; | |
levels.forEach(function (method) { | |
methods[method] = log(method.toUpperCase()); | |
}); | |
return methods; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment