2014-07-25 06:36:50 +00:00
|
|
|
var bunyan = require('../lib/bunyan');
|
2012-01-30 20:01:15 +00:00
|
|
|
|
2012-01-30 22:28:02 +00:00
|
|
|
// Basic usage.
|
2014-07-25 06:36:50 +00:00
|
|
|
var log = bunyan.createLogger({name: 'myapp', level: 'info', src: true});
|
2012-01-30 22:28:02 +00:00
|
|
|
|
|
|
|
// isInfoEnabled replacement
|
2012-06-05 06:19:39 +00:00
|
|
|
console.log('log.info() is:', log.info())
|
2012-01-30 22:28:02 +00:00
|
|
|
|
|
|
|
// `util.format`-based printf handling
|
2012-06-05 06:19:39 +00:00
|
|
|
log.info('hi');
|
|
|
|
log.info('hi', 'trent');
|
|
|
|
log.info('hi %s there', true);
|
2012-01-30 22:28:02 +00:00
|
|
|
|
|
|
|
// First arg as an object adds fields to the log record.
|
2012-06-05 06:19:39 +00:00
|
|
|
log.info({foo:'bar', multiline:'one\ntwo\nthree'}, 'hi %d', 1, 'two', 3);
|
2012-01-30 06:26:47 +00:00
|
|
|
|
|
|
|
|
2012-02-04 08:08:37 +00:00
|
|
|
// Shows `log.child(...)` to specialize a logger for a sub-component.
|
2012-06-05 06:19:39 +00:00
|
|
|
console.log('\n')
|
2012-01-30 06:26:47 +00:00
|
|
|
|
2012-01-30 20:01:15 +00:00
|
|
|
function Wuzzle(options) {
|
2013-03-29 00:42:32 +00:00
|
|
|
this.log = options.log;
|
|
|
|
this.log.info('creating a wuzzle')
|
2012-01-30 20:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Wuzzle.prototype.woos = function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
this.log.warn('This wuzzle is woosey.')
|
2012-01-30 20:01:15 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 06:19:39 +00:00
|
|
|
var wuzzle = new Wuzzle({log: log.child({component: 'wuzzle'})});
|
2012-01-30 20:01:15 +00:00
|
|
|
wuzzle.woos();
|
2012-06-05 06:19:39 +00:00
|
|
|
log.info('done with the wuzzle')
|