node-bunyan-lite/examples/hi.js
Trent Mick 6806112d8a - log.clone -> log.child to better reflect the relationship: streams and
serializers are inherited. Streams can't be removed as part of the child
  creation. The child doesn't own the parent's streams (so can't close them).
- Clean up Logger creation. The goal here was to ensure `log.child` usage
  is fast. TODO: measure that.
- Add `Logger.stdSerializers.err` serializer which is necessary to get good
  Error object logging with node 0.6 (where core Error object properties
  are non-enumerable).
2012-02-04 00:08:37 -08:00

33 lines
784 B
JavaScript

var Logger = require('../lib/bunyan');
// Basic usage.
var log = new Logger({service: "myapp", level: "info"});
// isInfoEnabled replacement
console.log("log.info() is:", log.info())
// `util.format`-based printf handling
log.info("hi");
log.info("hi", "trent");
log.info("hi %s there", true);
// First arg as an object adds fields to the log record.
log.info({foo:"bar"}, "hi %d", 1, "two", 3);
// Shows `log.child(...)` to specialize a logger for a sub-component.
console.log("\n\n")
function Wuzzle(options) {
this.log = options.log;
this.log.info("creating a wuzzle")
}
Wuzzle.prototype.woos = function () {
this.log.warn("This wuzzle is woosey.")
}
var wuzzle = new Wuzzle({log: log.child({component: "wuzzle"})});
wuzzle.woos();
log.info("done with the wuzzle")