node-bunyan-lite/examples/level.js

47 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

// Play with setting levels.
//
// TODO: put this in a damn test suite
var bunyan = require('../lib/bunyan'),
DEBUG = bunyan.DEBUG,
INFO = bunyan.INFO,
WARN = bunyan.WARN;
var assert = require('assert');
// Basic usage.
var log = bunyan.createLogger({
2013-03-29 00:42:32 +00:00
name: 'example-level',
streams: [
{
name: 'stdout',
stream: process.stdout,
level: 'debug'
},
{
name: 'stderr',
stream: process.stderr
}
]
});
assert.equal(log.level(), DEBUG);
assert.equal(log.levels()[0], DEBUG);
assert.equal(log.levels()[1], INFO);
assert.equal(log.levels(0), DEBUG);
assert.equal(log.levels(1), INFO);
assert.equal(log.levels('stdout'), DEBUG)
try {
2013-03-29 00:42:32 +00:00
log.levels('foo')
} catch (e) {
2013-03-29 00:42:32 +00:00
assert.ok(e.message.indexOf('name') !== -1)
}
2012-06-05 06:19:39 +00:00
log.trace('no one should see this')
log.debug('should see this once (on stdout)')
log.info('should see this twice')
log.levels('stdout', INFO)
2012-06-05 06:19:39 +00:00
log.debug('no one should see this either')
log.level('trace')
log.trace('should see this twice as 4th and 5th emitted log messages')