Skip to content

Instantly share code, notes, and snippets.

@blakmatrix
Created June 22, 2012 20:15
Show Gist options
  • Save blakmatrix/2974929 to your computer and use it in GitHub Desktop.
Save blakmatrix/2974929 to your computer and use it in GitHub Desktop.
bonsai logger
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