Skip to content

Instantly share code, notes, and snippets.

@tomgco
Created July 24, 2014 16:15
Show Gist options
  • Save tomgco/d9c5bfa898cd64754891 to your computer and use it in GitHub Desktop.
Save tomgco/d9c5bfa898cd64754891 to your computer and use it in GitHub Desktop.
var logger = require('logger')(module);
logger.info('Om nom nom');
// Same output
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