bunyan-formatter
Version:
Writable stream that formats bunyan records that are piped into it.
53 lines (42 loc) • 1.3 kB
JavaScript
;
var bunyan = require('bunyan')
, bformat = require('../')
, test = require('tap').test
;
function inspect(obj, depth) {
console.error(require('util').inspect(obj, false, depth || 5, true));
}
function removeTime(s) {
return s.substring(29);
}
describe('short mode', () => {
beforeAll(() => {
writes = [];
});
var formatOut = bformat({ outputMode: 'short'}, { write: onwrite })
var log = bunyan.createLogger({ name: 'app', stream: formatOut, level: 'debug' } );
var writes = [];
function onwrite (c) {
writes.push(c)
}
it('info', () => {
log.info('starting up');
expect(writes.map(removeTime)).toMatchSnapshot();
});
it('debug', () => {
log.debug('things are heating up', { temperature: 80, status: { started: 'yes', overheated: 'no' } });
expect(writes.map(removeTime)).toMatchSnapshot();
});
it('warn', () => {
log.warn('getting a bit hot', { temperature: 120 });
expect(writes.map(removeTime)).toMatchSnapshot();
})
it('error', () => {
log.error('OOOOHHH it burns!', new Error('temperature: 200'));
expect(writes.map(removeTime)).toMatchSnapshot();
})
it('fatal', () => {
log.fatal('I died! Do you know what that means???');
expect(writes.map(removeTime)).toMatchSnapshot();
});
});