Created
June 22, 2012 20:15
-
-
Save blakmatrix/2974929 to your computer and use it in GitHub Desktop.
bonsai logger
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 util = require('util'); | |
var Homer = module.exports = function (stream, format) { | |
var homer = this; | |
this.stream = stream; | |
this.format = format || function (lvl, msg) { | |
return util.format('[%s] %s', lvl, msg); | |
}; | |
// TODO: Expose customization | |
[ | |
'silly', | |
'debug', | |
'info', | |
'warn', | |
'D\'oh!' | |
].forEach(function (lvl) { | |
homer[lvl] = homer.log.bind(homer, lvl); | |
}); | |
}; | |
Homer.prototype.log = function () { | |
var args = [].slice.call(arguments), | |
lvl = args.shift(); | |
this.stream.write(this.format(util.format.call(args))); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment