node-bunyan-lite/examples/level.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

// Play with setting levels.
//
// TODO: put this in a damn test suite
var Logger = require('../lib/bunyan'),
2013-03-29 00:42:32 +00:00
DEBUG = Logger.DEBUG,
INFO = Logger.INFO,
WARN = Logger.WARN;
var assert = require('assert');
// Basic usage.
var log = new Logger({
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')