style: 4-space indents
This commit is contained in:
parent
7a6c3f5ce6
commit
f616276dc6
31 changed files with 2988 additions and 2988 deletions
2
Makefile
2
Makefile
|
@ -108,7 +108,7 @@ test06:
|
|||
|
||||
.PHONY: check-jsstyle
|
||||
check-jsstyle: $(JSSTYLE_FILES)
|
||||
./tools/jsstyle -o indent=2,doxygen,unparenthesized-return=0,blank-after-start-comment=0,leading-right-paren-ok $(JSSTYLE_FILES)
|
||||
./tools/jsstyle -o indent=4,doxygen,unparenthesized-return=0,blank-after-start-comment=0,leading-right-paren-ok $(JSSTYLE_FILES)
|
||||
|
||||
.PHONY: check
|
||||
check: check-jsstyle
|
||||
|
|
2202
bin/bunyan
2202
bin/bunyan
File diff suppressed because it is too large
Load diff
|
@ -5,25 +5,25 @@ var Logger = require('../lib/bunyan');
|
|||
var util = require('util');
|
||||
|
||||
var log = new Logger({
|
||||
name: 'myserver',
|
||||
serializers: {
|
||||
err: Logger.stdSerializers.err, // <--- use this
|
||||
}
|
||||
name: 'myserver',
|
||||
serializers: {
|
||||
err: Logger.stdSerializers.err, // <--- use this
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
throw new TypeError('boom');
|
||||
throw new TypeError('boom');
|
||||
} catch (err) {
|
||||
log.warn({err: err}, 'operation went boom: %s', err) // <--- here
|
||||
log.warn({err: err}, 'operation went boom: %s', err) // <--- here
|
||||
}
|
||||
|
||||
log.info(new TypeError('how about this?')) // <--- alternatively this
|
||||
|
||||
|
||||
try {
|
||||
throw 'boom string';
|
||||
throw 'boom string';
|
||||
} catch (err) {
|
||||
log.error(err)
|
||||
log.error(err)
|
||||
}
|
||||
|
||||
/* BEGIN JSSTYLED */
|
||||
|
|
|
@ -10,19 +10,19 @@ var S_IWUSR = 00200; // mask for owner write permission in stat mode
|
|||
|
||||
console.warn('- Log file is "%s".', FILENAME);
|
||||
if (!path.existsSync(FILENAME)) {
|
||||
console.warn('- Touch log file.');
|
||||
fs.writeFileSync(FILENAME, 'touch\n');
|
||||
console.warn('- Touch log file.');
|
||||
fs.writeFileSync(FILENAME, 'touch\n');
|
||||
}
|
||||
if (fs.statSync(FILENAME).mode & S_IWUSR) {
|
||||
console.warn('- Make log file read-only.');
|
||||
fs.chmodSync(FILENAME, 0444);
|
||||
console.warn('- Make log file read-only.');
|
||||
fs.chmodSync(FILENAME, 0444);
|
||||
}
|
||||
|
||||
console.warn('- Create logger.')
|
||||
var log = new Logger({name: 'handle-fs-error', streams: [{path: FILENAME}]});
|
||||
|
||||
log.on('error', function (err) {
|
||||
console.warn('- The logger emitted an error:', err);
|
||||
console.warn('- The logger emitted an error:', err);
|
||||
});
|
||||
|
||||
console.warn('- Call log.info(...).')
|
||||
|
@ -30,7 +30,7 @@ log.info('info log message');
|
|||
console.warn('- Called log.info(...).')
|
||||
|
||||
setTimeout(function () {
|
||||
console.warn('- Call log.warn(...).')
|
||||
log.warn('warn log message');
|
||||
console.warn('- Called log.warn(...).')
|
||||
console.warn('- Call log.warn(...).')
|
||||
log.warn('warn log message');
|
||||
console.warn('- Called log.warn(...).')
|
||||
}, 1000);
|
||||
|
|
|
@ -19,12 +19,12 @@ log.info({foo:'bar', multiline:'one\ntwo\nthree'}, 'hi %d', 1, 'two', 3);
|
|||
console.log('\n')
|
||||
|
||||
function Wuzzle(options) {
|
||||
this.log = options.log;
|
||||
this.log.info('creating a wuzzle')
|
||||
this.log = options.log;
|
||||
this.log.info('creating a wuzzle')
|
||||
}
|
||||
|
||||
Wuzzle.prototype.woos = function () {
|
||||
this.log.warn('This wuzzle is woosey.')
|
||||
this.log.warn('This wuzzle is woosey.')
|
||||
}
|
||||
|
||||
var wuzzle = new Wuzzle({log: log.child({component: 'wuzzle'})});
|
||||
|
|
|
@ -3,25 +3,25 @@
|
|||
// TODO: put this in a damn test suite
|
||||
|
||||
var Logger = require('../lib/bunyan'),
|
||||
DEBUG = Logger.DEBUG,
|
||||
INFO = Logger.INFO,
|
||||
WARN = Logger.WARN;
|
||||
DEBUG = Logger.DEBUG,
|
||||
INFO = Logger.INFO,
|
||||
WARN = Logger.WARN;
|
||||
var assert = require('assert');
|
||||
|
||||
// Basic usage.
|
||||
var log = new Logger({
|
||||
name: 'example-level',
|
||||
streams: [
|
||||
{
|
||||
name: 'stdout',
|
||||
stream: process.stdout,
|
||||
level: 'debug'
|
||||
},
|
||||
{
|
||||
name: 'stderr',
|
||||
stream: process.stderr
|
||||
}
|
||||
]
|
||||
name: 'example-level',
|
||||
streams: [
|
||||
{
|
||||
name: 'stdout',
|
||||
stream: process.stdout,
|
||||
level: 'debug'
|
||||
},
|
||||
{
|
||||
name: 'stderr',
|
||||
stream: process.stderr
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
assert.equal(log.level(), DEBUG);
|
||||
|
@ -32,9 +32,9 @@ assert.equal(log.levels(1), INFO);
|
|||
|
||||
assert.equal(log.levels('stdout'), DEBUG)
|
||||
try {
|
||||
log.levels('foo')
|
||||
log.levels('foo')
|
||||
} catch (e) {
|
||||
assert.ok(e.message.indexOf('name') !== -1)
|
||||
assert.ok(e.message.indexOf('name') !== -1)
|
||||
}
|
||||
|
||||
log.trace('no one should see this')
|
||||
|
|
|
@ -21,11 +21,11 @@ var bunyan = require('../lib/bunyan');
|
|||
|
||||
|
||||
function randint(n) {
|
||||
return Math.floor(Math.random() * n);
|
||||
return Math.floor(Math.random() * n);
|
||||
}
|
||||
|
||||
function randchoice(array) {
|
||||
return array[randint(array.length)];
|
||||
return array[randint(array.length)];
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,18 +40,18 @@ var log = bunyan.createLogger({name: 'lr', level: 'debug'});
|
|||
// We're logging to stdout. Let's exit gracefully on EPIPE. E.g. if piped
|
||||
// to `head` which will close after N lines.
|
||||
process.stdout.on('error', function (err) {
|
||||
if (err.code === 'EPIPE') {
|
||||
process.exit(0);
|
||||
}
|
||||
if (err.code === 'EPIPE') {
|
||||
process.exit(0);
|
||||
}
|
||||
})
|
||||
|
||||
function logOne() {
|
||||
var level = randchoice(levels);
|
||||
var msg = [randchoice(words), randchoice(words)].join(' ');
|
||||
var delay = randint(300);
|
||||
//console.warn('long-running about to log.%s(..., "%s")', level, msg)
|
||||
log[level]({'word': randchoice(words), 'delay': delay}, msg);
|
||||
timeout = setTimeout(logOne, delay);
|
||||
var level = randchoice(levels);
|
||||
var msg = [randchoice(words), randchoice(words)].join(' ');
|
||||
var delay = randint(300);
|
||||
//console.warn('long-running about to log.%s(..., "%s")', level, msg)
|
||||
log[level]({'word': randchoice(words), 'delay': delay}, msg);
|
||||
timeout = setTimeout(logOne, delay);
|
||||
}
|
||||
|
||||
log.info('hi, this is the start');
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
var Logger = require('../lib/bunyan');
|
||||
log = new Logger({
|
||||
name: 'amon',
|
||||
streams: [
|
||||
{
|
||||
level: 'info',
|
||||
stream: process.stdout,
|
||||
},
|
||||
{
|
||||
level: 'error',
|
||||
path: 'multi.log'
|
||||
}
|
||||
]
|
||||
name: 'amon',
|
||||
streams: [
|
||||
{
|
||||
level: 'info',
|
||||
stream: process.stdout,
|
||||
},
|
||||
{
|
||||
level: 'error',
|
||||
path: 'multi.log'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -11,25 +11,25 @@ var Logger = require('../lib/bunyan');
|
|||
*/
|
||||
function MyRawStream() {}
|
||||
MyRawStream.prototype.write = function (rec) {
|
||||
if (typeof (rec) !== 'object') {
|
||||
console.error('error: raw stream got a non-object record: %j', rec)
|
||||
} else {
|
||||
rec.yo = 'yo';
|
||||
process.stdout.write(JSON.stringify(rec) + '\n');
|
||||
}
|
||||
if (typeof (rec) !== 'object') {
|
||||
console.error('error: raw stream got a non-object record: %j', rec)
|
||||
} else {
|
||||
rec.yo = 'yo';
|
||||
process.stdout.write(JSON.stringify(rec) + '\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// A Logger using the raw stream.
|
||||
var log = new Logger({
|
||||
name: 'raw-example',
|
||||
streams: [
|
||||
{
|
||||
level: 'info',
|
||||
stream: new MyRawStream(),
|
||||
type: 'raw'
|
||||
},
|
||||
]
|
||||
name: 'raw-example',
|
||||
streams: [
|
||||
{
|
||||
level: 'info',
|
||||
stream: new MyRawStream(),
|
||||
type: 'raw'
|
||||
},
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
var bunyan = require('..');
|
||||
var ringbuffer = new bunyan.RingBuffer({ limit: 100 });
|
||||
var log = new bunyan({
|
||||
name: 'foo',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: ringbuffer,
|
||||
level: 'debug'
|
||||
} ]
|
||||
name: 'foo',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: ringbuffer,
|
||||
level: 'debug'
|
||||
} ]
|
||||
});
|
||||
|
||||
log.info('hello world');
|
||||
|
|
|
@ -4,37 +4,37 @@ var http = require('http');
|
|||
var Logger = require('../lib/bunyan');
|
||||
|
||||
var log = new Logger({
|
||||
name: 'myserver',
|
||||
serializers: {
|
||||
req: Logger.stdSerializers.req,
|
||||
res: Logger.stdSerializers.res
|
||||
}
|
||||
name: 'myserver',
|
||||
serializers: {
|
||||
req: Logger.stdSerializers.req,
|
||||
res: Logger.stdSerializers.res
|
||||
}
|
||||
});
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
log.info({req: req}, 'start request'); // <-- this is the guy we're testing
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
log.info({res: res}, 'done response'); // <-- this is the guy we're testing
|
||||
log.info({req: req}, 'start request'); // <-- this is the guy we're testing
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
log.info({res: res}, 'done response'); // <-- this is the guy we're testing
|
||||
});
|
||||
server.listen(1337, '127.0.0.1', function () {
|
||||
log.info('server listening');
|
||||
var options = {
|
||||
port: 1337,
|
||||
hostname: '127.0.0.1',
|
||||
path: '/path?q=1#anchor',
|
||||
headers: {
|
||||
'X-Hi': 'Mom'
|
||||
}
|
||||
};
|
||||
var req = http.request(options);
|
||||
req.on('response', function (res) {
|
||||
res.on('end', function () {
|
||||
process.exit();
|
||||
})
|
||||
});
|
||||
req.write('hi from the client');
|
||||
req.end();
|
||||
log.info('server listening');
|
||||
var options = {
|
||||
port: 1337,
|
||||
hostname: '127.0.0.1',
|
||||
path: '/path?q=1#anchor',
|
||||
headers: {
|
||||
'X-Hi': 'Mom'
|
||||
}
|
||||
};
|
||||
var req = http.request(options);
|
||||
req.on('response', function (res) {
|
||||
res.on('end', function () {
|
||||
process.exit();
|
||||
})
|
||||
});
|
||||
req.write('hi from the client');
|
||||
req.end();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -8,16 +8,16 @@ var log = new Logger({name: 'src-example', src: true});
|
|||
log.info('one');
|
||||
log.info('two');
|
||||
function doSomeFoo() {
|
||||
log.info({foo:'bar'}, 'three');
|
||||
log.info({foo:'bar'}, 'three');
|
||||
}
|
||||
doSomeFoo();
|
||||
|
||||
function Wuzzle(options) {
|
||||
this.log = options.log;
|
||||
this.log.info('creating a wuzzle')
|
||||
this.log = options.log;
|
||||
this.log.info('creating a wuzzle')
|
||||
}
|
||||
Wuzzle.prototype.woos = function () {
|
||||
this.log.warn('This wuzzle is woosey.')
|
||||
this.log.warn('This wuzzle is woosey.')
|
||||
}
|
||||
|
||||
var wuzzle = new Wuzzle({log: log.child({component: 'wuzzle'})});
|
||||
|
|
|
@ -5,7 +5,7 @@ var log = new Logger({src: true, name: 'foo'});
|
|||
|
||||
// Make a circular object (cannot be JSON-ified).
|
||||
var myobj = {
|
||||
foo: 'bar'
|
||||
foo: 'bar'
|
||||
};
|
||||
myobj.myobj = myobj;
|
||||
|
||||
|
|
1502
lib/bunyan.js
1502
lib/bunyan.js
File diff suppressed because it is too large
Load diff
|
@ -6,13 +6,13 @@
|
|||
*/
|
||||
|
||||
var util = require('util'),
|
||||
inspect = util.inspect,
|
||||
format = util.format;
|
||||
inspect = util.inspect,
|
||||
format = util.format;
|
||||
var bunyan = require('../lib/bunyan');
|
||||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -21,45 +21,45 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
function Catcher() {
|
||||
this.records = [];
|
||||
this.records = [];
|
||||
}
|
||||
Catcher.prototype.write = function (record) {
|
||||
this.records.push(record);
|
||||
this.records.push(record);
|
||||
}
|
||||
|
||||
var catcher = new Catcher();
|
||||
var log = new bunyan.createLogger({
|
||||
name: 'buffer.test',
|
||||
streams: [
|
||||
{
|
||||
type: 'raw',
|
||||
stream: catcher,
|
||||
level: 'trace'
|
||||
}
|
||||
]
|
||||
name: 'buffer.test',
|
||||
streams: [
|
||||
{
|
||||
type: 'raw',
|
||||
stream: catcher,
|
||||
level: 'trace'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
test('log.info(BUFFER)', function (t) {
|
||||
var b = new Buffer('foo');
|
||||
var b = new Buffer('foo');
|
||||
|
||||
['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(function (lvl) {
|
||||
log[lvl].call(log, b);
|
||||
var rec = catcher.records[catcher.records.length - 1];
|
||||
t.equal(rec.msg, inspect(b),
|
||||
format('log.%s msg is inspect(BUFFER)', lvl));
|
||||
t.ok(rec['0'] === undefined,
|
||||
'no "0" array index key in record: ' + inspect(rec['0']));
|
||||
t.ok(rec['parent'] === undefined,
|
||||
'no "parent" array index key in record: ' + inspect(rec['parent']));
|
||||
['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(function (lvl) {
|
||||
log[lvl].call(log, b);
|
||||
var rec = catcher.records[catcher.records.length - 1];
|
||||
t.equal(rec.msg, inspect(b),
|
||||
format('log.%s msg is inspect(BUFFER)', lvl));
|
||||
t.ok(rec['0'] === undefined,
|
||||
'no "0" array index key in record: ' + inspect(rec['0']));
|
||||
t.ok(rec['parent'] === undefined,
|
||||
'no "parent" array index key in record: ' + inspect(rec['parent']));
|
||||
|
||||
log[lvl].call(log, b, 'bar');
|
||||
var rec = catcher.records[catcher.records.length - 1];
|
||||
t.equal(rec.msg, inspect(b) + ' bar',
|
||||
format('log.%s(BUFFER, "bar") msg is inspect(BUFFER) + " bar"', lvl));
|
||||
});
|
||||
log[lvl].call(log, b, 'bar');
|
||||
var rec = catcher.records[catcher.records.length - 1];
|
||||
t.equal(rec.msg, inspect(b) + ' bar',
|
||||
format('log.%s(BUFFER, "bar") msg is inspect(BUFFER) + " bar"', lvl));
|
||||
});
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ var bunyan = require('../lib/bunyan');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -17,120 +17,120 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
function CapturingStream(recs) {
|
||||
this.recs = recs || [];
|
||||
this.recs = recs || [];
|
||||
}
|
||||
CapturingStream.prototype.write = function (rec) {
|
||||
this.recs.push(rec);
|
||||
this.recs.push(rec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
test('child can add stream', function (t) {
|
||||
var dadStream = new CapturingStream();
|
||||
var dad = bunyan.createLogger({
|
||||
name: 'surname',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: dadStream,
|
||||
level: 'info'
|
||||
} ]
|
||||
});
|
||||
var dadStream = new CapturingStream();
|
||||
var dad = bunyan.createLogger({
|
||||
name: 'surname',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: dadStream,
|
||||
level: 'info'
|
||||
} ]
|
||||
});
|
||||
|
||||
var sonStream = new CapturingStream();
|
||||
var son = dad.child({
|
||||
component: 'son',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: sonStream,
|
||||
level: 'debug'
|
||||
} ]
|
||||
});
|
||||
var sonStream = new CapturingStream();
|
||||
var son = dad.child({
|
||||
component: 'son',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: sonStream,
|
||||
level: 'debug'
|
||||
} ]
|
||||
});
|
||||
|
||||
dad.info('info from dad');
|
||||
dad.debug('debug from dad');
|
||||
son.debug('debug from son');
|
||||
dad.info('info from dad');
|
||||
dad.debug('debug from dad');
|
||||
son.debug('debug from son');
|
||||
|
||||
var rec;
|
||||
t.equal(dadStream.recs.length, 1);
|
||||
rec = dadStream.recs[0];
|
||||
t.equal(rec.msg, 'info from dad');
|
||||
t.equal(sonStream.recs.length, 1);
|
||||
rec = sonStream.recs[0];
|
||||
t.equal(rec.msg, 'debug from son');
|
||||
var rec;
|
||||
t.equal(dadStream.recs.length, 1);
|
||||
rec = dadStream.recs[0];
|
||||
t.equal(rec.msg, 'info from dad');
|
||||
t.equal(sonStream.recs.length, 1);
|
||||
rec = sonStream.recs[0];
|
||||
t.equal(rec.msg, 'debug from son');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('child can set level of inherited streams', function (t) {
|
||||
var dadStream = new CapturingStream();
|
||||
var dad = bunyan.createLogger({
|
||||
name: 'surname',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: dadStream,
|
||||
level: 'info'
|
||||
} ]
|
||||
});
|
||||
var dadStream = new CapturingStream();
|
||||
var dad = bunyan.createLogger({
|
||||
name: 'surname',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: dadStream,
|
||||
level: 'info'
|
||||
} ]
|
||||
});
|
||||
|
||||
// Intention here is that the inherited `dadStream` logs at 'debug' level
|
||||
// for the son.
|
||||
var son = dad.child({
|
||||
component: 'son',
|
||||
level: 'debug'
|
||||
});
|
||||
// Intention here is that the inherited `dadStream` logs at 'debug' level
|
||||
// for the son.
|
||||
var son = dad.child({
|
||||
component: 'son',
|
||||
level: 'debug'
|
||||
});
|
||||
|
||||
dad.info('info from dad');
|
||||
dad.debug('debug from dad');
|
||||
son.debug('debug from son');
|
||||
dad.info('info from dad');
|
||||
dad.debug('debug from dad');
|
||||
son.debug('debug from son');
|
||||
|
||||
var rec;
|
||||
t.equal(dadStream.recs.length, 2);
|
||||
rec = dadStream.recs[0];
|
||||
t.equal(rec.msg, 'info from dad');
|
||||
rec = dadStream.recs[1];
|
||||
t.equal(rec.msg, 'debug from son');
|
||||
var rec;
|
||||
t.equal(dadStream.recs.length, 2);
|
||||
rec = dadStream.recs[0];
|
||||
t.equal(rec.msg, 'info from dad');
|
||||
rec = dadStream.recs[1];
|
||||
t.equal(rec.msg, 'debug from son');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('child can set level of inherited streams and add streams', function (t) {
|
||||
var dadStream = new CapturingStream();
|
||||
var dad = bunyan.createLogger({
|
||||
name: 'surname',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: dadStream,
|
||||
level: 'info'
|
||||
} ]
|
||||
});
|
||||
var dadStream = new CapturingStream();
|
||||
var dad = bunyan.createLogger({
|
||||
name: 'surname',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: dadStream,
|
||||
level: 'info'
|
||||
} ]
|
||||
});
|
||||
|
||||
// Intention here is that the inherited `dadStream` logs at 'debug' level
|
||||
// for the son.
|
||||
var sonStream = new CapturingStream();
|
||||
var son = dad.child({
|
||||
component: 'son',
|
||||
level: 'trace',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: sonStream,
|
||||
level: 'debug'
|
||||
} ]
|
||||
});
|
||||
// Intention here is that the inherited `dadStream` logs at 'debug' level
|
||||
// for the son.
|
||||
var sonStream = new CapturingStream();
|
||||
var son = dad.child({
|
||||
component: 'son',
|
||||
level: 'trace',
|
||||
streams: [ {
|
||||
type: 'raw',
|
||||
stream: sonStream,
|
||||
level: 'debug'
|
||||
} ]
|
||||
});
|
||||
|
||||
dad.info('info from dad');
|
||||
dad.trace('trace from dad');
|
||||
son.trace('trace from son');
|
||||
son.debug('debug from son');
|
||||
dad.info('info from dad');
|
||||
dad.trace('trace from dad');
|
||||
son.trace('trace from son');
|
||||
son.debug('debug from son');
|
||||
|
||||
t.equal(dadStream.recs.length, 3);
|
||||
t.equal(dadStream.recs[0].msg, 'info from dad');
|
||||
t.equal(dadStream.recs[1].msg, 'trace from son');
|
||||
t.equal(dadStream.recs[2].msg, 'debug from son');
|
||||
t.equal(dadStream.recs.length, 3);
|
||||
t.equal(dadStream.recs[0].msg, 'info from dad');
|
||||
t.equal(dadStream.recs[1].msg, 'trace from son');
|
||||
t.equal(dadStream.recs[2].msg, 'debug from son');
|
||||
|
||||
t.equal(sonStream.recs.length, 1);
|
||||
t.equal(sonStream.recs[0].msg, 'debug from son');
|
||||
t.equal(sonStream.recs.length, 1);
|
||||
t.equal(sonStream.recs[0].msg, 'debug from son');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
|
522
test/cli.test.js
522
test/cli.test.js
|
@ -11,7 +11,7 @@ var debug = console.warn;
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -31,285 +31,285 @@ var BUNYAN = path.resolve(__dirname, '../bin/bunyan');
|
|||
//});
|
||||
|
||||
test('--version', function (t) {
|
||||
var version = require('../package.json').version;
|
||||
exec(BUNYAN + ' --version', function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout, 'bunyan ' + version + '\n');
|
||||
t.end();
|
||||
});
|
||||
var version = require('../package.json').version;
|
||||
exec(BUNYAN + ' --version', function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout, 'bunyan ' + version + '\n');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('--help', function (t) {
|
||||
exec(BUNYAN + ' --help', function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.ok(stdout.indexOf('General options:') !== -1);
|
||||
t.end();
|
||||
});
|
||||
exec(BUNYAN + ' --help', function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.ok(stdout.indexOf('General options:') !== -1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('-h', function (t) {
|
||||
exec(BUNYAN + ' -h', function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.ok(stdout.indexOf('General options:') !== -1);
|
||||
t.end();
|
||||
});
|
||||
exec(BUNYAN + ' -h', function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.ok(stdout.indexOf('General options:') !== -1);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('--bogus', function (t) {
|
||||
exec(BUNYAN + ' --bogus', function (err, stdout, stderr) {
|
||||
t.ok(err, 'should error out')
|
||||
t.equal(err.code, 1, '... with exit code 1')
|
||||
t.end();
|
||||
});
|
||||
exec(BUNYAN + ' --bogus', function (err, stdout, stderr) {
|
||||
t.ok(err, 'should error out')
|
||||
t.equal(err.code, 1, '... with exit code 1')
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('simple.log', function (t) {
|
||||
exec(_('%s %s/corpus/simple.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message\n');
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s %s/corpus/simple.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message\n');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
test('cat simple.log', function (t) {
|
||||
exec(_('cat %s/corpus/simple.log | %s', __dirname, BUNYAN),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message\n');
|
||||
t.end();
|
||||
}
|
||||
);
|
||||
exec(_('cat %s/corpus/simple.log | %s', __dirname, BUNYAN),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message\n');
|
||||
t.end();
|
||||
}
|
||||
);
|
||||
});
|
||||
test('simple.log with color', function (t) {
|
||||
exec(_('%s --color %s/corpus/simple.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
||||
+ 'on example.com: \u001b[36mMy message\u001b[39m\n\u001b[0m');
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s --color %s/corpus/simple.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
||||
+ 'on example.com: \u001b[36mMy message\u001b[39m\n\u001b[0m');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('extrafield.log', function (t) {
|
||||
exec(_('%s %s/corpus/extrafield.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message (extra=field)\n');
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s %s/corpus/extrafield.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message (extra=field)\n');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
test('extrafield.log with color', function (t) {
|
||||
exec(_('%s --color %s/corpus/extrafield.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
||||
+ 'on example.com: \u001b[36mMy message\u001b[39m'
|
||||
+ '\u001b[90m (extra=field)\u001b[39m\n\u001b[0m');
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s --color %s/corpus/extrafield.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
||||
+ 'on example.com: \u001b[36mMy message\u001b[39m'
|
||||
+ '\u001b[90m (extra=field)\u001b[39m\n\u001b[0m');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('bogus.log', function (t) {
|
||||
exec(_('%s %s/corpus/bogus.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n');
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s %s/corpus/bogus.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('bogus.log -j', function (t) {
|
||||
exec(_('%s -j %s/corpus/bogus.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n');
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s -j %s/corpus/bogus.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err)
|
||||
t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('all.log', function (t) {
|
||||
exec(_('%s %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
// Just make sure don't blow up on this.
|
||||
t.ifError(err)
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
// Just make sure don't blow up on this.
|
||||
t.ifError(err)
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('simple.log doesnotexist1.log doesnotexist2.log', function (t) {
|
||||
exec(_('%s %s/corpus/simple.log doesnotexist1.log doesnotexist2.log',
|
||||
BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ok(err)
|
||||
t.equal(err.code, 2)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message\n');
|
||||
// Note: node v0.6.10:
|
||||
// ENOENT, no such file or directory 'asdf.log'
|
||||
// but node v0.6.14:
|
||||
// ENOENT, open 'asdf.log'
|
||||
// Somewhat annoying change.
|
||||
t.equal(stderr,
|
||||
'bunyan: ENOENT, open \'doesnotexist1.log\'\nbunyan: ENOENT, '
|
||||
+ 'open \'doesnotexist2.log\'\n');
|
||||
t.end();
|
||||
}
|
||||
);
|
||||
exec(_('%s %s/corpus/simple.log doesnotexist1.log doesnotexist2.log',
|
||||
BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ok(err)
|
||||
t.equal(err.code, 2)
|
||||
t.equal(stdout,
|
||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||
+ 'My message\n');
|
||||
// Note: node v0.6.10:
|
||||
// ENOENT, no such file or directory 'asdf.log'
|
||||
// but node v0.6.14:
|
||||
// ENOENT, open 'asdf.log'
|
||||
// Somewhat annoying change.
|
||||
t.equal(stderr,
|
||||
'bunyan: ENOENT, open \'doesnotexist1.log\'\nbunyan: ENOENT, '
|
||||
+ 'open \'doesnotexist2.log\'\n');
|
||||
t.end();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('multiple logs', function (t) {
|
||||
exec(_('%s %s/corpus/log1.log %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:01:49.339Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:47.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:57.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:08:01.105Z] INFO: agent2/76156 on headnode: message\n',
|
||||
].join(''));
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s %s/corpus/log1.log %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:01:49.339Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:47.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:57.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:08:01.105Z] INFO: agent2/76156 on headnode: message\n',
|
||||
].join(''));
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('multiple logs, bunyan format', function (t) {
|
||||
exec(_('%s -o bunyan %s/corpus/log1.log %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:57:55.586Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:58:55.586Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:01:49.339Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:47.404Z","v":0}',
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.339Z","v":0}',
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}',
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:57.404Z","v":0}',
|
||||
'{"name":"agent2","pid":76156,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:08:01.105Z","v":0}',
|
||||
''
|
||||
].join('\n'));
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s -o bunyan %s/corpus/log1.log %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:57:55.586Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T16:58:55.586Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:01:49.339Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:47.404Z","v":0}',
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.339Z","v":0}',
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}',
|
||||
'{"name":"agent1","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:49.404Z","v":0}',
|
||||
'{"name":"agent2","pid":73267,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:02:57.404Z","v":0}',
|
||||
'{"name":"agent2","pid":76156,"hostname":"headnode","level":30,"msg":"message","time":"2012-05-08T17:08:01.105Z","v":0}',
|
||||
''
|
||||
].join('\n'));
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('log1.log.gz', function (t) {
|
||||
exec(_('%s %s/corpus/log1.log.gz', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
].join(''));
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s %s/corpus/log1.log.gz', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
].join(''));
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('mixed text and gzip logs', function (t) {
|
||||
exec(_('%s %s/corpus/log1.log.gz %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:01:49.339Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:47.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:57.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:08:01.105Z] INFO: agent2/76156 on headnode: message\n',
|
||||
].join(''));
|
||||
t.end();
|
||||
});
|
||||
exec(_('%s %s/corpus/log1.log.gz %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, [
|
||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:01:49.339Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:47.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:49.404Z] INFO: agent1/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:02:57.404Z] INFO: agent2/73267 on headnode: message\n',
|
||||
'[2012-05-08T17:08:01.105Z] INFO: agent2/76156 on headnode: message\n',
|
||||
].join(''));
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('--level 40', function (t) {
|
||||
expect = [
|
||||
'# levels\n',
|
||||
'[2012-02-08T22:56:53.856Z] WARN: myservice/123 on example.com: My message\n',
|
||||
'[2012-02-08T22:56:54.856Z] ERROR: myservice/123 on example.com: My message\n',
|
||||
'[2012-02-08T22:56:55.856Z] LVL55: myservice/123 on example.com: My message\n',
|
||||
'[2012-02-08T22:56:56.856Z] FATAL: myservice/123 on example.com: My message\n',
|
||||
'\n',
|
||||
'# extra fields\n',
|
||||
'\n',
|
||||
'# bogus\n',
|
||||
'not a JSON line\n',
|
||||
'{"hi": "there"}\n'
|
||||
].join('');
|
||||
exec(_('%s -l 40 %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
exec(_('%s --level 40 %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
expect = [
|
||||
'# levels\n',
|
||||
'[2012-02-08T22:56:53.856Z] WARN: myservice/123 on example.com: My message\n',
|
||||
'[2012-02-08T22:56:54.856Z] ERROR: myservice/123 on example.com: My message\n',
|
||||
'[2012-02-08T22:56:55.856Z] LVL55: myservice/123 on example.com: My message\n',
|
||||
'[2012-02-08T22:56:56.856Z] FATAL: myservice/123 on example.com: My message\n',
|
||||
'\n',
|
||||
'# extra fields\n',
|
||||
'\n',
|
||||
'# bogus\n',
|
||||
'not a JSON line\n',
|
||||
'{"hi": "there"}\n'
|
||||
].join('');
|
||||
exec(_('%s -l 40 %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
exec(_('%s --level 40 %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('--condition "level === 10 && pid === 123"', function (t) {
|
||||
var expect = [
|
||||
'# levels\n',
|
||||
'[2012-02-08T22:56:50.856Z] TRACE: myservice/123 on example.com: My message\n',
|
||||
'\n',
|
||||
'# extra fields\n',
|
||||
'\n',
|
||||
'# bogus\n',
|
||||
'not a JSON line\n',
|
||||
'{"hi": "there"}\n'
|
||||
].join('');
|
||||
exec(_('%s -c "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
exec(_('%s --condition "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
var expect = [
|
||||
'# levels\n',
|
||||
'[2012-02-08T22:56:50.856Z] TRACE: myservice/123 on example.com: My message\n',
|
||||
'\n',
|
||||
'# extra fields\n',
|
||||
'\n',
|
||||
'# bogus\n',
|
||||
'not a JSON line\n',
|
||||
'{"hi": "there"}\n'
|
||||
].join('');
|
||||
exec(_('%s -c "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
exec(_('%s --condition "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// multiple
|
||||
// not sure if this is a bug or a feature. let's call it a feature!
|
||||
test('multiple --conditions', function (t) {
|
||||
var expect = [
|
||||
'# levels\n',
|
||||
'[2012-02-08T22:56:53.856Z] WARN: myservice/1 on example.com: My message\n',
|
||||
'\n',
|
||||
'# extra fields\n',
|
||||
'\n',
|
||||
'# bogus\n',
|
||||
'not a JSON line\n',
|
||||
'{"hi": "there"}\n'
|
||||
].join('');
|
||||
exec(_('%s %s/corpus/all.log ' +
|
||||
'-c "if (level === 40) pid = 1; true" ' +
|
||||
'-c "pid === 1"', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
});
|
||||
var expect = [
|
||||
'# levels\n',
|
||||
'[2012-02-08T22:56:53.856Z] WARN: myservice/1 on example.com: My message\n',
|
||||
'\n',
|
||||
'# extra fields\n',
|
||||
'\n',
|
||||
'# bogus\n',
|
||||
'not a JSON line\n',
|
||||
'{"hi": "there"}\n'
|
||||
].join('');
|
||||
exec(_('%s %s/corpus/all.log ' +
|
||||
'-c "if (level === 40) pid = 1; true" ' +
|
||||
'-c "pid === 1"', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
// https://github.com/trentm/node-bunyan/issues/30
|
||||
|
@ -317,43 +317,43 @@ test('multiple --conditions', function (t) {
|
|||
// One of the records in corpus/withreq.log has a 'req'
|
||||
// field with no 'headers'. Ditto for the 'res' field.
|
||||
test('robust req handling', function (t) {
|
||||
var expect = [
|
||||
'[2012-08-08T10:25:47.636Z] DEBUG: amon-master/12859 on 9724a190-27b6-4fd8-830b-a574f839c67d: headAgentProbes respond (req_id=cce79d15-ffc2-487c-a4e4-e940bdaac31e, route=HeadAgentProbes, contentMD5=11FxOYiYfpMxmANj4kGJzg==)',
|
||||
'[2012-08-08T10:25:47.637Z] INFO: amon-master/12859 on 9724a190-27b6-4fd8-830b-a574f839c67d: HeadAgentProbes handled: 200 (req_id=cce79d15-ffc2-487c-a4e4-e940bdaac31e, audit=true, remoteAddress=10.2.207.2, remotePort=50394, latency=3, secure=false, _audit=true, req.version=*)',
|
||||
' HEAD /agentprobes?agent=ccf92af9-0b24-46b6-ab60-65095fdd3037 HTTP/1.1',
|
||||
' accept: application/json',
|
||||
' content-type: application/json',
|
||||
' host: 10.2.207.16',
|
||||
' connection: keep-alive',
|
||||
' --',
|
||||
' HTTP/1.1 200 OK',
|
||||
' content-md5: 11FxOYiYfpMxmANj4kGJzg==',
|
||||
' access-control-allow-origin: *',
|
||||
' access-control-allow-headers: Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
|
||||
' access-control-allow-methods: HEAD',
|
||||
' access-control-expose-headers: X-Api-Version, X-Request-Id, X-Response-Time',
|
||||
' connection: Keep-Alive',
|
||||
' date: Wed, 08 Aug 2012 10:25:47 GMT',
|
||||
' server: Amon Master/1.0.0',
|
||||
' x-request-id: cce79d15-ffc2-487c-a4e4-e940bdaac31e',
|
||||
' x-response-time: 3',
|
||||
' --',
|
||||
' route: {',
|
||||
' "name": "HeadAgentProbes",',
|
||||
' "version": false',
|
||||
' }',
|
||||
'[2012-08-08T10:25:47.637Z] INFO: amon-master/12859 on 9724a190-27b6-4fd8-830b-a574f839c67d: HeadAgentProbes handled: 200 (req_id=cce79d15-ffc2-487c-a4e4-e940bdaac31e, audit=true, remoteAddress=10.2.207.2, remotePort=50394, latency=3, secure=false, _audit=true, req.version=*)',
|
||||
' HEAD /agentprobes?agent=ccf92af9-0b24-46b6-ab60-65095fdd3037 HTTP/1.1',
|
||||
' --',
|
||||
' route: {',
|
||||
' "name": "HeadAgentProbes",',
|
||||
' "version": false',
|
||||
' }'
|
||||
].join('\n') + '\n';
|
||||
exec(_('%s %s/corpus/withreq.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
});
|
||||
var expect = [
|
||||
'[2012-08-08T10:25:47.636Z] DEBUG: amon-master/12859 on 9724a190-27b6-4fd8-830b-a574f839c67d: headAgentProbes respond (req_id=cce79d15-ffc2-487c-a4e4-e940bdaac31e, route=HeadAgentProbes, contentMD5=11FxOYiYfpMxmANj4kGJzg==)',
|
||||
'[2012-08-08T10:25:47.637Z] INFO: amon-master/12859 on 9724a190-27b6-4fd8-830b-a574f839c67d: HeadAgentProbes handled: 200 (req_id=cce79d15-ffc2-487c-a4e4-e940bdaac31e, audit=true, remoteAddress=10.2.207.2, remotePort=50394, latency=3, secure=false, _audit=true, req.version=*)',
|
||||
' HEAD /agentprobes?agent=ccf92af9-0b24-46b6-ab60-65095fdd3037 HTTP/1.1',
|
||||
' accept: application/json',
|
||||
' content-type: application/json',
|
||||
' host: 10.2.207.16',
|
||||
' connection: keep-alive',
|
||||
' --',
|
||||
' HTTP/1.1 200 OK',
|
||||
' content-md5: 11FxOYiYfpMxmANj4kGJzg==',
|
||||
' access-control-allow-origin: *',
|
||||
' access-control-allow-headers: Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
|
||||
' access-control-allow-methods: HEAD',
|
||||
' access-control-expose-headers: X-Api-Version, X-Request-Id, X-Response-Time',
|
||||
' connection: Keep-Alive',
|
||||
' date: Wed, 08 Aug 2012 10:25:47 GMT',
|
||||
' server: Amon Master/1.0.0',
|
||||
' x-request-id: cce79d15-ffc2-487c-a4e4-e940bdaac31e',
|
||||
' x-response-time: 3',
|
||||
' --',
|
||||
' route: {',
|
||||
' "name": "HeadAgentProbes",',
|
||||
' "version": false',
|
||||
' }',
|
||||
'[2012-08-08T10:25:47.637Z] INFO: amon-master/12859 on 9724a190-27b6-4fd8-830b-a574f839c67d: HeadAgentProbes handled: 200 (req_id=cce79d15-ffc2-487c-a4e4-e940bdaac31e, audit=true, remoteAddress=10.2.207.2, remotePort=50394, latency=3, secure=false, _audit=true, req.version=*)',
|
||||
' HEAD /agentprobes?agent=ccf92af9-0b24-46b6-ab60-65095fdd3037 HTTP/1.1',
|
||||
' --',
|
||||
' route: {',
|
||||
' "name": "HeadAgentProbes",',
|
||||
' "version": false',
|
||||
' }'
|
||||
].join('\n') + '\n';
|
||||
exec(_('%s %s/corpus/withreq.log', BUNYAN, __dirname),
|
||||
function (err, stdout, stderr) {
|
||||
t.ifError(err);
|
||||
t.equal(stdout, expect);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
*/
|
||||
|
||||
var bunyan = require('../lib/bunyan'),
|
||||
Logger = bunyan;
|
||||
Logger = bunyan;
|
||||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -18,109 +18,109 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
test('ensure Logger creation options', function (t) {
|
||||
t.throws(function () { new Logger(); },
|
||||
'options (object) is required',
|
||||
'no options should throw');
|
||||
t.throws(function () { new Logger(); },
|
||||
'options (object) is required',
|
||||
'no options should throw');
|
||||
|
||||
t.throws(function () { new Logger({}); },
|
||||
'options.name (string) is required',
|
||||
'no options.name should throw');
|
||||
t.throws(function () { new Logger({}); },
|
||||
'options.name (string) is required',
|
||||
'no options.name should throw');
|
||||
|
||||
t.doesNotThrow(function () { new Logger({name: 'foo'}); },
|
||||
'just options.name should be sufficient');
|
||||
t.doesNotThrow(function () { new Logger({name: 'foo'}); },
|
||||
'just options.name should be sufficient');
|
||||
|
||||
var options = {name: 'foo', stream: process.stdout, streams: []};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'cannot use "stream" and "streams"');
|
||||
var options = {name: 'foo', stream: process.stdout, streams: []};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'cannot use "stream" and "streams"');
|
||||
|
||||
// https://github.com/trentm/node-bunyan/issues/3
|
||||
options = {name: 'foo', streams: {}};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'invalid options.streams: must be an array',
|
||||
'"streams" must be an array');
|
||||
// https://github.com/trentm/node-bunyan/issues/3
|
||||
options = {name: 'foo', streams: {}};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'invalid options.streams: must be an array',
|
||||
'"streams" must be an array');
|
||||
|
||||
options = {name: 'foo', serializers: 'a string'};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be a string');
|
||||
options = {name: 'foo', serializers: 'a string'};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be a string');
|
||||
|
||||
options = {name: 'foo', serializers: [1, 2, 3]};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be an array');
|
||||
options = {name: 'foo', serializers: [1, 2, 3]};
|
||||
t.throws(function () { new Logger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be an array');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('ensure Logger creation options (createLogger)', function (t) {
|
||||
t.throws(function () { bunyan.createLogger(); },
|
||||
'options (object) is required',
|
||||
'no options should throw');
|
||||
t.throws(function () { bunyan.createLogger(); },
|
||||
'options (object) is required',
|
||||
'no options should throw');
|
||||
|
||||
t.throws(function () { bunyan.createLogger({}); },
|
||||
'options.name (string) is required',
|
||||
'no options.name should throw');
|
||||
t.throws(function () { bunyan.createLogger({}); },
|
||||
'options.name (string) is required',
|
||||
'no options.name should throw');
|
||||
|
||||
t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
|
||||
'just options.name should be sufficient');
|
||||
t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
|
||||
'just options.name should be sufficient');
|
||||
|
||||
var options = {name: 'foo', stream: process.stdout, streams: []};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'cannot use "stream" and "streams"');
|
||||
var options = {name: 'foo', stream: process.stdout, streams: []};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'cannot use "stream" and "streams"');
|
||||
|
||||
// https://github.com/trentm/node-bunyan/issues/3
|
||||
options = {name: 'foo', streams: {}};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'invalid options.streams: must be an array',
|
||||
'"streams" must be an array');
|
||||
// https://github.com/trentm/node-bunyan/issues/3
|
||||
options = {name: 'foo', streams: {}};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'invalid options.streams: must be an array',
|
||||
'"streams" must be an array');
|
||||
|
||||
options = {name: 'foo', serializers: 'a string'};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be a string');
|
||||
options = {name: 'foo', serializers: 'a string'};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be a string');
|
||||
|
||||
options = {name: 'foo', serializers: [1, 2, 3]};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be an array');
|
||||
options = {name: 'foo', serializers: [1, 2, 3]};
|
||||
t.throws(function () { bunyan.createLogger(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be an array');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('ensure Logger child() options', function (t) {
|
||||
var log = new Logger({name: 'foo'});
|
||||
var log = new Logger({name: 'foo'});
|
||||
|
||||
t.doesNotThrow(function () { log.child(); },
|
||||
'no options should be fine');
|
||||
t.doesNotThrow(function () { log.child(); },
|
||||
'no options should be fine');
|
||||
|
||||
t.doesNotThrow(function () { log.child({}); },
|
||||
'empty options should be fine too');
|
||||
t.doesNotThrow(function () { log.child({}); },
|
||||
'empty options should be fine too');
|
||||
|
||||
t.throws(function () { log.child({name: 'foo'}); },
|
||||
'invalid options.name: child cannot set logger name',
|
||||
'child cannot change name');
|
||||
t.throws(function () { log.child({name: 'foo'}); },
|
||||
'invalid options.name: child cannot set logger name',
|
||||
'child cannot change name');
|
||||
|
||||
var options = {stream: process.stdout, streams: []};
|
||||
t.throws(function () { log.child(options); },
|
||||
'cannot use "stream" and "streams"');
|
||||
var options = {stream: process.stdout, streams: []};
|
||||
t.throws(function () { log.child(options); },
|
||||
'cannot use "stream" and "streams"');
|
||||
|
||||
// https://github.com/trentm/node-bunyan/issues/3
|
||||
options = {streams: {}};
|
||||
t.throws(function () { log.child(options); },
|
||||
'invalid options.streams: must be an array',
|
||||
'"streams" must be an array');
|
||||
// https://github.com/trentm/node-bunyan/issues/3
|
||||
options = {streams: {}};
|
||||
t.throws(function () { log.child(options); },
|
||||
'invalid options.streams: must be an array',
|
||||
'"streams" must be an array');
|
||||
|
||||
options = {serializers: 'a string'};
|
||||
t.throws(function () { log.child(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be a string');
|
||||
options = {serializers: 'a string'};
|
||||
t.throws(function () { log.child(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be a string');
|
||||
|
||||
options = {serializers: [1, 2, 3]};
|
||||
t.throws(function () { log.child(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be an array');
|
||||
options = {serializers: [1, 2, 3]};
|
||||
t.throws(function () { log.child(options); },
|
||||
'invalid options.serializers: must be an object',
|
||||
'"serializers" cannot be an array');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
|
|
@ -8,7 +8,7 @@ var Logger = require('../lib/bunyan.js');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -20,71 +20,71 @@ var outstr = new Stream;
|
|||
outstr.writable = true;
|
||||
var output = [];
|
||||
outstr.write = function (c) {
|
||||
output.push(JSON.parse(c + ''));
|
||||
output.push(JSON.parse(c + ''));
|
||||
};
|
||||
outstr.end = function (c) {
|
||||
if (c) this.write(c);
|
||||
this.emit('end');
|
||||
if (c) this.write(c);
|
||||
this.emit('end');
|
||||
};
|
||||
|
||||
// these are lacking a few fields that will probably never match
|
||||
var expect =
|
||||
[
|
||||
{
|
||||
'name': 'blammo',
|
||||
'level': 30,
|
||||
'msg': 'bango { bang: \'boom\', KABOOM: [Circular] }',
|
||||
'v': 0
|
||||
},
|
||||
{
|
||||
'name': 'blammo',
|
||||
'level': 30,
|
||||
'msg': 'kaboom { bang: \'boom\', KABOOM: [Circular] }',
|
||||
'v': 0
|
||||
},
|
||||
{
|
||||
'name': 'blammo',
|
||||
'level': 30,
|
||||
'bang': 'boom',
|
||||
'KABOOM': {
|
||||
'bang': 'boom',
|
||||
'KABOOM': '[Circular]'
|
||||
},
|
||||
'msg': '',
|
||||
'v': 0
|
||||
}
|
||||
];
|
||||
[
|
||||
{
|
||||
'name': 'blammo',
|
||||
'level': 30,
|
||||
'msg': 'bango { bang: \'boom\', KABOOM: [Circular] }',
|
||||
'v': 0
|
||||
},
|
||||
{
|
||||
'name': 'blammo',
|
||||
'level': 30,
|
||||
'msg': 'kaboom { bang: \'boom\', KABOOM: [Circular] }',
|
||||
'v': 0
|
||||
},
|
||||
{
|
||||
'name': 'blammo',
|
||||
'level': 30,
|
||||
'bang': 'boom',
|
||||
'KABOOM': {
|
||||
'bang': 'boom',
|
||||
'KABOOM': '[Circular]'
|
||||
},
|
||||
'msg': '',
|
||||
'v': 0
|
||||
}
|
||||
];
|
||||
|
||||
var log = new Logger({
|
||||
name: 'blammo',
|
||||
streams: [
|
||||
{
|
||||
type: 'stream',
|
||||
level: 'info',
|
||||
stream: outstr
|
||||
}
|
||||
]
|
||||
name: 'blammo',
|
||||
streams: [
|
||||
{
|
||||
type: 'stream',
|
||||
level: 'info',
|
||||
stream: outstr
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
test('cycles', function (t) {
|
||||
outstr.on('end', function () {
|
||||
output.forEach(function (o, i) {
|
||||
// Drop variable parts for comparison.
|
||||
delete o.hostname;
|
||||
delete o.pid;
|
||||
delete o.time;
|
||||
// Hack object/dict comparison: JSONify.
|
||||
t.equal(JSON.stringify(o), JSON.stringify(expect[i]),
|
||||
'log item ' + i + ' matches');
|
||||
outstr.on('end', function () {
|
||||
output.forEach(function (o, i) {
|
||||
// Drop variable parts for comparison.
|
||||
delete o.hostname;
|
||||
delete o.pid;
|
||||
delete o.time;
|
||||
// Hack object/dict comparison: JSONify.
|
||||
t.equal(JSON.stringify(o), JSON.stringify(expect[i]),
|
||||
'log item ' + i + ' matches');
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
var obj = { bang: 'boom' };
|
||||
obj.KABOOM = obj;
|
||||
log.info('bango', obj);
|
||||
log.info('kaboom', obj.KABOOM);
|
||||
log.info(obj);
|
||||
outstr.end();
|
||||
t.ok('did not throw');
|
||||
var obj = { bang: 'boom' };
|
||||
obj.KABOOM = obj;
|
||||
log.info('bango', obj);
|
||||
log.info('kaboom', obj.KABOOM);
|
||||
log.info(obj);
|
||||
outstr.end();
|
||||
t.ok('did not throw');
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ var bunyan = require('../lib/bunyan');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -22,55 +22,55 @@ var test = tap4nodeunit.test;
|
|||
var dtracePlats = ['sunos', 'darwin', 'freebsd'];
|
||||
var runDtraceTests = true;
|
||||
try {
|
||||
require('dtrace-provider')
|
||||
require('dtrace-provider')
|
||||
} catch (e) {
|
||||
console.log('# skip dtrace tests: no dtrace-provider module');
|
||||
runDtraceTests = false;
|
||||
console.log('# skip dtrace tests: no dtrace-provider module');
|
||||
runDtraceTests = false;
|
||||
}
|
||||
if (!runDtraceTests) {
|
||||
/* pass through */
|
||||
/* pass through */
|
||||
} else if (dtracePlats.indexOf(process.platform) === -1) {
|
||||
console.log('# skip dtrace tests: not on a platform with dtrace');
|
||||
runDtraceTests = false;
|
||||
console.log('# skip dtrace tests: not on a platform with dtrace');
|
||||
runDtraceTests = false;
|
||||
} else if (process.env.SKIP_DTRACE) {
|
||||
console.log('# skip dtrace tests: SKIP_DTRACE envvar set');
|
||||
runDtraceTests = false;
|
||||
console.log('# skip dtrace tests: SKIP_DTRACE envvar set');
|
||||
runDtraceTests = false;
|
||||
} else if (process.getgid() !== 0) {
|
||||
console.log('# skip dtrace tests: gid is not 0, run with `sudo`');
|
||||
runDtraceTests = false;
|
||||
console.log('# skip dtrace tests: gid is not 0, run with `sudo`');
|
||||
runDtraceTests = false;
|
||||
}
|
||||
if (runDtraceTests) {
|
||||
|
||||
|
||||
test('basic dtrace', function (t) {
|
||||
var argv = ['dtrace', '-Z', '-x', 'strsize=4k', '-qn',
|
||||
'bunyan$target:::log-*{printf("%s", copyinstr(arg0))}',
|
||||
'-c', format('node %s/log-some.js', __dirname)];
|
||||
var dtrace = spawn(argv[0], argv.slice(1));
|
||||
//console.error('ARGV: %j', argv);
|
||||
var argv = ['dtrace', '-Z', '-x', 'strsize=4k', '-qn',
|
||||
'bunyan$target:::log-*{printf("%s", copyinstr(arg0))}',
|
||||
'-c', format('node %s/log-some.js', __dirname)];
|
||||
var dtrace = spawn(argv[0], argv.slice(1));
|
||||
//console.error('ARGV: %j', argv);
|
||||
|
||||
var traces = [];
|
||||
dtrace.stdout.on('data', function (data) {
|
||||
//console.error('DTRACE STDOUT:', data.toString());
|
||||
traces.push(data.toString());
|
||||
});
|
||||
dtrace.stderr.on('data', function (data) {
|
||||
console.error('DTRACE STDERR:', data.toString());
|
||||
});
|
||||
dtrace.on('exit', function (code) {
|
||||
t.notOk(code, 'dtrace exited cleanly');
|
||||
traces = traces.join('').split('\n')
|
||||
.filter(function (t) { return t.trim().length })
|
||||
.map(function (t) { return JSON.parse(t) });
|
||||
t.equal(traces.length, 2, 'got 2 log records');
|
||||
if (traces.length) {
|
||||
t.equal(traces[0].level, bunyan.DEBUG);
|
||||
t.equal(traces[0].foo, 'bar');
|
||||
t.equal(traces[1].level, bunyan.TRACE);
|
||||
t.equal(traces[1].msg, 'hi at trace');
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
var traces = [];
|
||||
dtrace.stdout.on('data', function (data) {
|
||||
//console.error('DTRACE STDOUT:', data.toString());
|
||||
traces.push(data.toString());
|
||||
});
|
||||
dtrace.stderr.on('data', function (data) {
|
||||
console.error('DTRACE STDERR:', data.toString());
|
||||
});
|
||||
dtrace.on('exit', function (code) {
|
||||
t.notOk(code, 'dtrace exited cleanly');
|
||||
traces = traces.join('').split('\n')
|
||||
.filter(function (t) { return t.trim().length })
|
||||
.map(function (t) { return JSON.parse(t) });
|
||||
t.equal(traces.length, 2, 'got 2 log records');
|
||||
if (traces.length) {
|
||||
t.equal(traces[0].level, bunyan.DEBUG);
|
||||
t.equal(traces[0].foo, 'bar');
|
||||
t.equal(traces[1].level, bunyan.TRACE);
|
||||
t.equal(traces[1].msg, 'hi at trace');
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ var bunyan = require('../lib/bunyan');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -17,16 +17,16 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
test('error event on log write', function (t) {
|
||||
LOG_PATH = '/this/path/is/bogus.log'
|
||||
var log = bunyan.createLogger(
|
||||
{name: 'error-event', streams: [ {path: LOG_PATH} ]});
|
||||
log.on('error', function (err, stream) {
|
||||
t.ok(err, 'got err in error event: ' + err);
|
||||
t.equal(err.code, 'ENOENT', 'error code is ENOENT');
|
||||
t.ok(stream, 'got a stream argument');
|
||||
t.equal(stream.path, LOG_PATH);
|
||||
t.equal(stream.type, 'file');
|
||||
t.end();
|
||||
});
|
||||
log.info('info log message');
|
||||
LOG_PATH = '/this/path/is/bogus.log'
|
||||
var log = bunyan.createLogger(
|
||||
{name: 'error-event', streams: [ {path: LOG_PATH} ]});
|
||||
log.on('error', function (err, stream) {
|
||||
t.ok(err, 'got err in error event: ' + err);
|
||||
t.equal(err.code, 'ENOENT', 'error code is ENOENT');
|
||||
t.ok(stream, 'got a stream argument');
|
||||
t.equal(stream.path, LOG_PATH);
|
||||
t.equal(stream.type, 'file');
|
||||
t.end();
|
||||
});
|
||||
log.info('info log message');
|
||||
});
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
var bunyan = require('../lib/bunyan');
|
||||
var log = bunyan.createLogger({
|
||||
name: 'play',
|
||||
serializers: bunyan.stdSerializers
|
||||
name: 'play',
|
||||
serializers: bunyan.stdSerializers
|
||||
});
|
||||
log.debug({foo: 'bar'}, 'hi at debug')
|
||||
log.trace('hi at trace')
|
||||
|
|
|
@ -8,7 +8,7 @@ var bunyan = require('../lib/bunyan');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -16,45 +16,45 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
var log1 = bunyan.createLogger({
|
||||
name: 'log1',
|
||||
streams: [
|
||||
{
|
||||
path: __dirname + '/log.test.log1.log',
|
||||
level: 'info'
|
||||
}
|
||||
]
|
||||
name: 'log1',
|
||||
streams: [
|
||||
{
|
||||
path: __dirname + '/log.test.log1.log',
|
||||
level: 'info'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
var log2 = bunyan.createLogger({
|
||||
name: 'log2',
|
||||
streams: [
|
||||
{
|
||||
path: __dirname + '/log.test.log2a.log',
|
||||
level: 'error'
|
||||
},
|
||||
{
|
||||
path: __dirname + '/log.test.log2b.log',
|
||||
level: 'debug'
|
||||
}
|
||||
]
|
||||
name: 'log2',
|
||||
streams: [
|
||||
{
|
||||
path: __dirname + '/log.test.log2a.log',
|
||||
level: 'error'
|
||||
},
|
||||
{
|
||||
path: __dirname + '/log.test.log2b.log',
|
||||
level: 'debug'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
test('log.LEVEL() -> boolean', function (t) {
|
||||
t.equal(log1.trace(), false, 'log1.trace() is false')
|
||||
t.equal(log1.debug(), false)
|
||||
t.equal(log1.info(), true)
|
||||
t.equal(log1.warn(), true)
|
||||
t.equal(log1.error(), true)
|
||||
t.equal(log1.fatal(), true)
|
||||
t.equal(log1.trace(), false, 'log1.trace() is false')
|
||||
t.equal(log1.debug(), false)
|
||||
t.equal(log1.info(), true)
|
||||
t.equal(log1.warn(), true)
|
||||
t.equal(log1.error(), true)
|
||||
t.equal(log1.fatal(), true)
|
||||
|
||||
// Level is the *lowest* level of all streams.
|
||||
t.equal(log2.trace(), false)
|
||||
t.equal(log2.debug(), true)
|
||||
t.equal(log2.info(), true)
|
||||
t.equal(log2.warn(), true)
|
||||
t.equal(log2.error(), true)
|
||||
t.equal(log2.fatal(), true)
|
||||
t.end();
|
||||
// Level is the *lowest* level of all streams.
|
||||
t.equal(log2.trace(), false)
|
||||
t.equal(log2.debug(), true)
|
||||
t.equal(log2.info(), true)
|
||||
t.equal(log2.warn(), true)
|
||||
t.equal(log2.error(), true)
|
||||
t.equal(log2.fatal(), true)
|
||||
t.end();
|
||||
});
|
||||
|
||||
//TODO:
|
||||
|
|
|
@ -8,7 +8,7 @@ var bunyan = require('../lib/bunyan');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -16,27 +16,27 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
test('bunyan.<LEVEL>s', function (t) {
|
||||
t.ok(bunyan.TRACE, 'TRACE');
|
||||
t.ok(bunyan.DEBUG, 'DEBUG');
|
||||
t.ok(bunyan.INFO, 'INFO');
|
||||
t.ok(bunyan.WARN, 'WARN');
|
||||
t.ok(bunyan.ERROR, 'ERROR');
|
||||
t.ok(bunyan.FATAL, 'FATAL');
|
||||
t.end();
|
||||
t.ok(bunyan.TRACE, 'TRACE');
|
||||
t.ok(bunyan.DEBUG, 'DEBUG');
|
||||
t.ok(bunyan.INFO, 'INFO');
|
||||
t.ok(bunyan.WARN, 'WARN');
|
||||
t.ok(bunyan.ERROR, 'ERROR');
|
||||
t.ok(bunyan.FATAL, 'FATAL');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('bunyan.resolveLevel()', function (t) {
|
||||
t.equal(bunyan.resolveLevel('trace'), bunyan.TRACE, 'TRACE');
|
||||
t.equal(bunyan.resolveLevel('TRACE'), bunyan.TRACE, 'TRACE');
|
||||
t.equal(bunyan.resolveLevel('debug'), bunyan.DEBUG, 'DEBUG');
|
||||
t.equal(bunyan.resolveLevel('DEBUG'), bunyan.DEBUG, 'DEBUG');
|
||||
t.equal(bunyan.resolveLevel('info'), bunyan.INFO, 'INFO');
|
||||
t.equal(bunyan.resolveLevel('INFO'), bunyan.INFO, 'INFO');
|
||||
t.equal(bunyan.resolveLevel('warn'), bunyan.WARN, 'WARN');
|
||||
t.equal(bunyan.resolveLevel('WARN'), bunyan.WARN, 'WARN');
|
||||
t.equal(bunyan.resolveLevel('error'), bunyan.ERROR, 'ERROR');
|
||||
t.equal(bunyan.resolveLevel('ERROR'), bunyan.ERROR, 'ERROR');
|
||||
t.equal(bunyan.resolveLevel('fatal'), bunyan.FATAL, 'FATAL');
|
||||
t.equal(bunyan.resolveLevel('FATAL'), bunyan.FATAL, 'FATAL');
|
||||
t.end();
|
||||
t.equal(bunyan.resolveLevel('trace'), bunyan.TRACE, 'TRACE');
|
||||
t.equal(bunyan.resolveLevel('TRACE'), bunyan.TRACE, 'TRACE');
|
||||
t.equal(bunyan.resolveLevel('debug'), bunyan.DEBUG, 'DEBUG');
|
||||
t.equal(bunyan.resolveLevel('DEBUG'), bunyan.DEBUG, 'DEBUG');
|
||||
t.equal(bunyan.resolveLevel('info'), bunyan.INFO, 'INFO');
|
||||
t.equal(bunyan.resolveLevel('INFO'), bunyan.INFO, 'INFO');
|
||||
t.equal(bunyan.resolveLevel('warn'), bunyan.WARN, 'WARN');
|
||||
t.equal(bunyan.resolveLevel('WARN'), bunyan.WARN, 'WARN');
|
||||
t.equal(bunyan.resolveLevel('error'), bunyan.ERROR, 'ERROR');
|
||||
t.equal(bunyan.resolveLevel('ERROR'), bunyan.ERROR, 'ERROR');
|
||||
t.equal(bunyan.resolveLevel('fatal'), bunyan.FATAL, 'FATAL');
|
||||
t.equal(bunyan.resolveLevel('FATAL'), bunyan.FATAL, 'FATAL');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ var Logger = require('../lib/bunyan');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -17,101 +17,101 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
function CapturingStream(recs) {
|
||||
this.recs = recs;
|
||||
this.recs = recs;
|
||||
}
|
||||
CapturingStream.prototype.write = function (rec) {
|
||||
this.recs.push(rec);
|
||||
this.recs.push(rec);
|
||||
}
|
||||
|
||||
|
||||
test('raw stream', function (t) {
|
||||
var recs = [];
|
||||
var recs = [];
|
||||
|
||||
var log = new Logger({
|
||||
name: 'raw-stream-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(recs),
|
||||
type: 'raw'
|
||||
}
|
||||
]
|
||||
});
|
||||
log.info('first');
|
||||
log.info({two: 'deux'}, 'second');
|
||||
var log = new Logger({
|
||||
name: 'raw-stream-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(recs),
|
||||
type: 'raw'
|
||||
}
|
||||
]
|
||||
});
|
||||
log.info('first');
|
||||
log.info({two: 'deux'}, 'second');
|
||||
|
||||
t.equal(recs.length, 2);
|
||||
t.equal(typeof (recs[0]), 'object', 'first rec is an object');
|
||||
t.equal(recs[1].two, 'deux', '"two" field made it through');
|
||||
t.end();
|
||||
t.equal(recs.length, 2);
|
||||
t.equal(typeof (recs[0]), 'object', 'first rec is an object');
|
||||
t.equal(recs[1].two, 'deux', '"two" field made it through');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('raw streams and regular streams can mix', function (t) {
|
||||
var rawRecs = [];
|
||||
var nonRawRecs = [];
|
||||
var rawRecs = [];
|
||||
var nonRawRecs = [];
|
||||
|
||||
var log = new Logger({
|
||||
name: 'raw-stream-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(rawRecs),
|
||||
type: 'raw'
|
||||
},
|
||||
{
|
||||
stream: new CapturingStream(nonRawRecs)
|
||||
}
|
||||
]
|
||||
});
|
||||
log.info('first');
|
||||
log.info({two: 'deux'}, 'second');
|
||||
var log = new Logger({
|
||||
name: 'raw-stream-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(rawRecs),
|
||||
type: 'raw'
|
||||
},
|
||||
{
|
||||
stream: new CapturingStream(nonRawRecs)
|
||||
}
|
||||
]
|
||||
});
|
||||
log.info('first');
|
||||
log.info({two: 'deux'}, 'second');
|
||||
|
||||
t.equal(rawRecs.length, 2);
|
||||
t.equal(typeof (rawRecs[0]), 'object', 'first rawRec is an object');
|
||||
t.equal(rawRecs[1].two, 'deux', '"two" field made it through');
|
||||
t.equal(rawRecs.length, 2);
|
||||
t.equal(typeof (rawRecs[0]), 'object', 'first rawRec is an object');
|
||||
t.equal(rawRecs[1].two, 'deux', '"two" field made it through');
|
||||
|
||||
t.equal(nonRawRecs.length, 2);
|
||||
t.equal(typeof (nonRawRecs[0]), 'string', 'first nonRawRec is a string');
|
||||
t.equal(nonRawRecs.length, 2);
|
||||
t.equal(typeof (nonRawRecs[0]), 'string', 'first nonRawRec is a string');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('child adding a non-raw stream works', function (t) {
|
||||
var parentRawRecs = [];
|
||||
var rawRecs = [];
|
||||
var nonRawRecs = [];
|
||||
var parentRawRecs = [];
|
||||
var rawRecs = [];
|
||||
var nonRawRecs = [];
|
||||
|
||||
var logParent = new Logger({
|
||||
name: 'raw-stream-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(parentRawRecs),
|
||||
type: 'raw'
|
||||
}
|
||||
]
|
||||
});
|
||||
var logChild = logParent.child({
|
||||
child: true,
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(rawRecs),
|
||||
type: 'raw'
|
||||
},
|
||||
{
|
||||
stream: new CapturingStream(nonRawRecs)
|
||||
}
|
||||
]
|
||||
});
|
||||
logParent.info('first');
|
||||
logChild.info({two: 'deux'}, 'second');
|
||||
var logParent = new Logger({
|
||||
name: 'raw-stream-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(parentRawRecs),
|
||||
type: 'raw'
|
||||
}
|
||||
]
|
||||
});
|
||||
var logChild = logParent.child({
|
||||
child: true,
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(rawRecs),
|
||||
type: 'raw'
|
||||
},
|
||||
{
|
||||
stream: new CapturingStream(nonRawRecs)
|
||||
}
|
||||
]
|
||||
});
|
||||
logParent.info('first');
|
||||
logChild.info({two: 'deux'}, 'second');
|
||||
|
||||
t.equal(rawRecs.length, 1,
|
||||
format('rawRecs length should be 1 (is %d)', rawRecs.length));
|
||||
t.equal(typeof (rawRecs[0]), 'object', 'rawRec entry is an object');
|
||||
t.equal(rawRecs[0].two, 'deux', '"two" field made it through');
|
||||
t.equal(rawRecs.length, 1,
|
||||
format('rawRecs length should be 1 (is %d)', rawRecs.length));
|
||||
t.equal(typeof (rawRecs[0]), 'object', 'rawRec entry is an object');
|
||||
t.equal(rawRecs[0].two, 'deux', '"two" field made it through');
|
||||
|
||||
t.equal(nonRawRecs.length, 1);
|
||||
t.equal(typeof (nonRawRecs[0]), 'string', 'first nonRawRec is a string');
|
||||
t.equal(nonRawRecs.length, 1);
|
||||
t.equal(typeof (nonRawRecs[0]), 'string', 'first nonRawRec is a string');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ var ringbuffer = new Logger.RingBuffer({ 'limit': 5 });
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -15,33 +15,33 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
var log1 = new Logger({
|
||||
name: 'log1',
|
||||
streams: [
|
||||
{
|
||||
stream: ringbuffer,
|
||||
type: 'raw',
|
||||
level: 'info'
|
||||
}
|
||||
]
|
||||
name: 'log1',
|
||||
streams: [
|
||||
{
|
||||
stream: ringbuffer,
|
||||
type: 'raw',
|
||||
level: 'info'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
test('ringbuffer', function (t) {
|
||||
log1.info('hello');
|
||||
log1.trace('there');
|
||||
log1.error('android');
|
||||
t.equal(ringbuffer.records.length, 2);
|
||||
t.equal(ringbuffer.records[0]['msg'], 'hello');
|
||||
t.equal(ringbuffer.records[1]['msg'], 'android');
|
||||
log1.error('one');
|
||||
log1.error('two');
|
||||
log1.error('three');
|
||||
t.equal(ringbuffer.records.length, 5);
|
||||
log1.error('four');
|
||||
t.equal(ringbuffer.records.length, 5);
|
||||
t.equal(ringbuffer.records[0]['msg'], 'android');
|
||||
t.equal(ringbuffer.records[1]['msg'], 'one');
|
||||
t.equal(ringbuffer.records[2]['msg'], 'two');
|
||||
t.equal(ringbuffer.records[3]['msg'], 'three');
|
||||
t.equal(ringbuffer.records[4]['msg'], 'four');
|
||||
t.end();
|
||||
log1.info('hello');
|
||||
log1.trace('there');
|
||||
log1.error('android');
|
||||
t.equal(ringbuffer.records.length, 2);
|
||||
t.equal(ringbuffer.records[0]['msg'], 'hello');
|
||||
t.equal(ringbuffer.records[1]['msg'], 'android');
|
||||
log1.error('one');
|
||||
log1.error('two');
|
||||
log1.error('three');
|
||||
t.equal(ringbuffer.records.length, 5);
|
||||
log1.error('four');
|
||||
t.equal(ringbuffer.records.length, 5);
|
||||
t.equal(ringbuffer.records[0]['msg'], 'android');
|
||||
t.equal(ringbuffer.records[1]['msg'], 'one');
|
||||
t.equal(ringbuffer.records[2]['msg'], 'two');
|
||||
t.equal(ringbuffer.records[3]['msg'], 'three');
|
||||
t.equal(ringbuffer.records[4]['msg'], 'four');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ var verror = require('verror');
|
|||
|
||||
// node-tap API
|
||||
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||
var after = tap4nodeunit.after;
|
||||
var before = tap4nodeunit.before;
|
||||
|
@ -19,246 +19,246 @@ var test = tap4nodeunit.test;
|
|||
|
||||
|
||||
function CapturingStream(recs) {
|
||||
this.recs = recs;
|
||||
this.recs = recs;
|
||||
}
|
||||
CapturingStream.prototype.write = function (rec) {
|
||||
this.recs.push(rec);
|
||||
this.recs.push(rec);
|
||||
}
|
||||
|
||||
|
||||
test('req serializer', function (t) {
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
req: bunyan.stdSerializers.req
|
||||
}
|
||||
});
|
||||
|
||||
// None of these should blow up.
|
||||
var bogusReqs = [
|
||||
undefined,
|
||||
null,
|
||||
{},
|
||||
1,
|
||||
'string',
|
||||
[1, 2, 3],
|
||||
{'foo':'bar'}
|
||||
];
|
||||
for (var i = 0; i < bogusReqs.length; i++) {
|
||||
log.info({req: bogusReqs[i]}, 'hi');
|
||||
t.equal(records[i].req, bogusReqs[i]);
|
||||
}
|
||||
|
||||
// Get http request and response objects to play with and test.
|
||||
var theReq, theRes;
|
||||
var server = http.createServer(function (req, res) {
|
||||
theReq = req;
|
||||
theRes = res;
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
})
|
||||
server.listen(8765, function () {
|
||||
http.get({host: '127.0.0.1', port: 8765, path: '/'}, function (res) {
|
||||
res.resume();
|
||||
log.info({req: theReq}, 'the request');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.req.method, 'GET');
|
||||
t.equal(lastRecord.req.url, theReq.url);
|
||||
t.equal(lastRecord.req.remoteAddress, theReq.connection.remoteAddress);
|
||||
t.equal(lastRecord.req.remotePort, theReq.connection.remotePort);
|
||||
server.close();
|
||||
t.end();
|
||||
}).on('error', function (err) {
|
||||
t.ok(false, 'error requesting to our test server: ' + err);
|
||||
server.close();
|
||||
t.end();
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
req: bunyan.stdSerializers.req
|
||||
}
|
||||
});
|
||||
|
||||
// None of these should blow up.
|
||||
var bogusReqs = [
|
||||
undefined,
|
||||
null,
|
||||
{},
|
||||
1,
|
||||
'string',
|
||||
[1, 2, 3],
|
||||
{'foo':'bar'}
|
||||
];
|
||||
for (var i = 0; i < bogusReqs.length; i++) {
|
||||
log.info({req: bogusReqs[i]}, 'hi');
|
||||
t.equal(records[i].req, bogusReqs[i]);
|
||||
}
|
||||
|
||||
// Get http request and response objects to play with and test.
|
||||
var theReq, theRes;
|
||||
var server = http.createServer(function (req, res) {
|
||||
theReq = req;
|
||||
theRes = res;
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
})
|
||||
server.listen(8765, function () {
|
||||
http.get({host: '127.0.0.1', port: 8765, path: '/'}, function (res) {
|
||||
res.resume();
|
||||
log.info({req: theReq}, 'the request');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.req.method, 'GET');
|
||||
t.equal(lastRecord.req.url, theReq.url);
|
||||
t.equal(lastRecord.req.remoteAddress, theReq.connection.remoteAddress);
|
||||
t.equal(lastRecord.req.remotePort, theReq.connection.remotePort);
|
||||
server.close();
|
||||
t.end();
|
||||
}).on('error', function (err) {
|
||||
t.ok(false, 'error requesting to our test server: ' + err);
|
||||
server.close();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('res serializer', function (t) {
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
res: bunyan.stdSerializers.res
|
||||
}
|
||||
});
|
||||
|
||||
// None of these should blow up.
|
||||
var bogusRess = [
|
||||
undefined,
|
||||
null,
|
||||
{},
|
||||
1,
|
||||
'string',
|
||||
[1, 2, 3],
|
||||
{'foo':'bar'}
|
||||
];
|
||||
for (var i = 0; i < bogusRess.length; i++) {
|
||||
log.info({res: bogusRess[i]}, 'hi');
|
||||
t.equal(records[i].res, bogusRess[i]);
|
||||
}
|
||||
|
||||
// Get http request and response objects to play with and test.
|
||||
var theReq, theRes;
|
||||
var server = http.createServer(function (req, res) {
|
||||
theReq = req;
|
||||
theRes = res;
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
})
|
||||
server.listen(8765, function () {
|
||||
http.get({host: '127.0.0.1', port: 8765, path: '/'}, function (res) {
|
||||
res.resume();
|
||||
log.info({res: theRes}, 'the response');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.res.statusCode, theRes.statusCode);
|
||||
t.equal(lastRecord.res.header, theRes._header);
|
||||
server.close();
|
||||
t.end();
|
||||
}).on('error', function (err) {
|
||||
t.ok(false, 'error requesting to our test server: ' + err);
|
||||
server.close();
|
||||
t.end();
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
res: bunyan.stdSerializers.res
|
||||
}
|
||||
});
|
||||
|
||||
// None of these should blow up.
|
||||
var bogusRess = [
|
||||
undefined,
|
||||
null,
|
||||
{},
|
||||
1,
|
||||
'string',
|
||||
[1, 2, 3],
|
||||
{'foo':'bar'}
|
||||
];
|
||||
for (var i = 0; i < bogusRess.length; i++) {
|
||||
log.info({res: bogusRess[i]}, 'hi');
|
||||
t.equal(records[i].res, bogusRess[i]);
|
||||
}
|
||||
|
||||
// Get http request and response objects to play with and test.
|
||||
var theReq, theRes;
|
||||
var server = http.createServer(function (req, res) {
|
||||
theReq = req;
|
||||
theRes = res;
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
})
|
||||
server.listen(8765, function () {
|
||||
http.get({host: '127.0.0.1', port: 8765, path: '/'}, function (res) {
|
||||
res.resume();
|
||||
log.info({res: theRes}, 'the response');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.res.statusCode, theRes.statusCode);
|
||||
t.equal(lastRecord.res.header, theRes._header);
|
||||
server.close();
|
||||
t.end();
|
||||
}).on('error', function (err) {
|
||||
t.ok(false, 'error requesting to our test server: ' + err);
|
||||
server.close();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('err serializer', function (t) {
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
err: bunyan.stdSerializers.err
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [
|
||||
{
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
err: bunyan.stdSerializers.err
|
||||
}
|
||||
});
|
||||
|
||||
// None of these should blow up.
|
||||
var bogusErrs = [
|
||||
undefined,
|
||||
null,
|
||||
{},
|
||||
1,
|
||||
'string',
|
||||
[1, 2, 3],
|
||||
{'foo':'bar'}
|
||||
];
|
||||
for (var i = 0; i < bogusErrs.length; i++) {
|
||||
log.info({err: bogusErrs[i]}, 'hi');
|
||||
t.equal(records[i].err, bogusErrs[i]);
|
||||
}
|
||||
});
|
||||
|
||||
// None of these should blow up.
|
||||
var bogusErrs = [
|
||||
undefined,
|
||||
null,
|
||||
{},
|
||||
1,
|
||||
'string',
|
||||
[1, 2, 3],
|
||||
{'foo':'bar'}
|
||||
];
|
||||
for (var i = 0; i < bogusErrs.length; i++) {
|
||||
log.info({err: bogusErrs[i]}, 'hi');
|
||||
t.equal(records[i].err, bogusErrs[i]);
|
||||
}
|
||||
var theErr = new TypeError('blah');
|
||||
|
||||
var theErr = new TypeError('blah');
|
||||
|
||||
log.info(theErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, theErr.message);
|
||||
t.equal(lastRecord.err.name, theErr.name);
|
||||
t.equal(lastRecord.err.stack, theErr.stack);
|
||||
t.end();
|
||||
log.info(theErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, theErr.message);
|
||||
t.equal(lastRecord.err.name, theErr.name);
|
||||
t.equal(lastRecord.err.stack, theErr.stack);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('err serializer: long stack', function (t) {
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [ {
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
} ],
|
||||
serializers: {
|
||||
err: bunyan.stdSerializers.err
|
||||
}
|
||||
});
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [ {
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
} ],
|
||||
serializers: {
|
||||
err: bunyan.stdSerializers.err
|
||||
}
|
||||
});
|
||||
|
||||
var topErr, midErr, bottomErr;
|
||||
var topErr, midErr, bottomErr;
|
||||
|
||||
// Just a VError.
|
||||
topErr = new verror.VError('top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'Just a VError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'Just a VError');
|
||||
t.equal(lastRecord.err.stack, topErr.stack, 'Just a VError');
|
||||
// Just a VError.
|
||||
topErr = new verror.VError('top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'Just a VError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'Just a VError');
|
||||
t.equal(lastRecord.err.stack, topErr.stack, 'Just a VError');
|
||||
|
||||
// Just a WError.
|
||||
topErr = new verror.WError('top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'Just a WError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'Just a WError');
|
||||
t.equal(lastRecord.err.stack, topErr.stack, 'Just a WError');
|
||||
// Just a WError.
|
||||
topErr = new verror.WError('top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'Just a WError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'Just a WError');
|
||||
t.equal(lastRecord.err.stack, topErr.stack, 'Just a WError');
|
||||
|
||||
// WError <- TypeError
|
||||
bottomErr = new TypeError('bottom err');
|
||||
topErr = new verror.WError(bottomErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- TypeError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- TypeError');
|
||||
var expectedStack = topErr.stack + '\nCaused by: ' + bottomErr.stack;
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- TypeError');
|
||||
// WError <- TypeError
|
||||
bottomErr = new TypeError('bottom err');
|
||||
topErr = new verror.WError(bottomErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- TypeError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- TypeError');
|
||||
var expectedStack = topErr.stack + '\nCaused by: ' + bottomErr.stack;
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- TypeError');
|
||||
|
||||
// WError <- WError
|
||||
bottomErr = new verror.WError('bottom err');
|
||||
topErr = new verror.WError(bottomErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- WError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- WError');
|
||||
var expectedStack = topErr.stack + '\nCaused by: ' + bottomErr.stack;
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- WError');
|
||||
// WError <- WError
|
||||
bottomErr = new verror.WError('bottom err');
|
||||
topErr = new verror.WError(bottomErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- WError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- WError');
|
||||
var expectedStack = topErr.stack + '\nCaused by: ' + bottomErr.stack;
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- WError');
|
||||
|
||||
// WError <- WError <- TypeError
|
||||
bottomErr = new TypeError('bottom err');
|
||||
midErr = new verror.WError(bottomErr, 'mid err');
|
||||
topErr = new verror.WError(midErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- WError <- TypeError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- WError <- TypeError');
|
||||
var expectedStack = (topErr.stack
|
||||
+ '\nCaused by: ' + midErr.stack
|
||||
+ '\nCaused by: ' + bottomErr.stack);
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- WError <- TypeError');
|
||||
// WError <- WError <- TypeError
|
||||
bottomErr = new TypeError('bottom err');
|
||||
midErr = new verror.WError(bottomErr, 'mid err');
|
||||
topErr = new verror.WError(midErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- WError <- TypeError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- WError <- TypeError');
|
||||
var expectedStack = (topErr.stack
|
||||
+ '\nCaused by: ' + midErr.stack
|
||||
+ '\nCaused by: ' + bottomErr.stack);
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- WError <- TypeError');
|
||||
|
||||
// WError <- WError <- WError
|
||||
bottomErr = new verror.WError('bottom err');
|
||||
midErr = new verror.WError(bottomErr, 'mid err');
|
||||
topErr = new verror.WError(midErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- WError <- WError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- WError <- WError');
|
||||
var expectedStack = (topErr.stack
|
||||
+ '\nCaused by: ' + midErr.stack
|
||||
+ '\nCaused by: ' + bottomErr.stack);
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- WError <- WError');
|
||||
// WError <- WError <- WError
|
||||
bottomErr = new verror.WError('bottom err');
|
||||
midErr = new verror.WError(bottomErr, 'mid err');
|
||||
topErr = new verror.WError(midErr, 'top err');
|
||||
log.info(topErr, 'the error');
|
||||
var lastRecord = records[records.length-1];
|
||||
t.equal(lastRecord.err.message, topErr.message, 'WError <- WError <- WError');
|
||||
t.equal(lastRecord.err.name, topErr.name, 'WError <- WError <- WError');
|
||||
var expectedStack = (topErr.stack
|
||||
+ '\nCaused by: ' + midErr.stack
|
||||
+ '\nCaused by: ' + bottomErr.stack);
|
||||
t.equal(lastRecord.err.stack, expectedStack, 'WError <- WError <- WError');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
|
@ -266,28 +266,28 @@ test('err serializer: long stack', function (t) {
|
|||
// even if the log record doesn't have the associated key. That means
|
||||
// serializers that don't handle an `undefined` value will blow up.
|
||||
test('do not apply serializers if no record key', function (t) {
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [ {
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
} ],
|
||||
serializers: {
|
||||
err: bunyan.stdSerializers.err,
|
||||
boom: function (value) {
|
||||
throw new Error('boom');
|
||||
}
|
||||
}
|
||||
});
|
||||
var records = [];
|
||||
var log = bunyan.createLogger({
|
||||
name: 'serializer-test',
|
||||
streams: [ {
|
||||
stream: new CapturingStream(records),
|
||||
type: 'raw'
|
||||
} ],
|
||||
serializers: {
|
||||
err: bunyan.stdSerializers.err,
|
||||
boom: function (value) {
|
||||
throw new Error('boom');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
log.info({foo: 'bar'}, 'record one');
|
||||
log.info({err: new Error('record two err')}, 'record two');
|
||||
log.info({foo: 'bar'}, 'record one');
|
||||
log.info({err: new Error('record two err')}, 'record two');
|
||||
|
||||
t.equal(records[0].boom, undefined);
|
||||
t.equal(records[0].foo, 'bar');
|
||||
t.equal(records[1].boom, undefined);
|
||||
t.equal(records[1].err.message, 'record two err');
|
||||
t.equal(records[0].boom, undefined);
|
||||
t.equal(records[0].foo, 'bar');
|
||||
t.equal(records[1].boom, undefined);
|
||||
t.equal(records[1].err.message, 'record two err');
|
||||
|
||||
t.end();
|
||||
t.end();
|
||||
});
|
||||
|
|
|
@ -18,45 +18,45 @@
|
|||
|
||||
module.exports = {
|
||||
|
||||
after: function after(teardown) {
|
||||
module.parent.exports.tearDown = function _teardown(callback) {
|
||||
try {
|
||||
teardown.call(this, callback);
|
||||
} catch (e) {
|
||||
console.error('after:\n' + e.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
},
|
||||
after: function after(teardown) {
|
||||
module.parent.exports.tearDown = function _teardown(callback) {
|
||||
try {
|
||||
teardown.call(this, callback);
|
||||
} catch (e) {
|
||||
console.error('after:\n' + e.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
before: function before(setup) {
|
||||
module.parent.exports.setUp = function _setup(callback) {
|
||||
try {
|
||||
setup.call(this, callback);
|
||||
} catch (e) {
|
||||
console.error('before:\n' + e.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
},
|
||||
before: function before(setup) {
|
||||
module.parent.exports.setUp = function _setup(callback) {
|
||||
try {
|
||||
setup.call(this, callback);
|
||||
} catch (e) {
|
||||
console.error('before:\n' + e.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
test: function test(name, tester) {
|
||||
module.parent.exports[name] = function _(t) {
|
||||
var _done = false;
|
||||
t.end = function end() {
|
||||
if (!_done) {
|
||||
_done = true;
|
||||
t.done();
|
||||
}
|
||||
};
|
||||
t.notOk = function notOk(ok, message) {
|
||||
return (t.ok(!ok, message));
|
||||
};
|
||||
t.error = t.ifError;
|
||||
test: function test(name, tester) {
|
||||
module.parent.exports[name] = function _(t) {
|
||||
var _done = false;
|
||||
t.end = function end() {
|
||||
if (!_done) {
|
||||
_done = true;
|
||||
t.done();
|
||||
}
|
||||
};
|
||||
t.notOk = function notOk(ok, message) {
|
||||
return (t.ok(!ok, message));
|
||||
};
|
||||
t.error = t.ifError;
|
||||
|
||||
tester.call(this, t);
|
||||
};
|
||||
}
|
||||
tester.call(this, t);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -17,68 +17,68 @@ var ben = require('ben'); // npm install ben
|
|||
var Logger = require('../lib/bunyan');
|
||||
|
||||
var log = new Logger({
|
||||
name: 'svc',
|
||||
streams: [
|
||||
{
|
||||
path: __dirname + '/timechild.log'
|
||||
},
|
||||
{
|
||||
stream: process.stdout
|
||||
name: 'svc',
|
||||
streams: [
|
||||
{
|
||||
path: __dirname + '/timechild.log'
|
||||
},
|
||||
{
|
||||
stream: process.stdout
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
err: Logger.stdSerializers.err
|
||||
}
|
||||
],
|
||||
serializers: {
|
||||
err: Logger.stdSerializers.err
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Time `log.child`:');
|
||||
|
||||
var ms = ben(1e5, function () {
|
||||
var child = log.child();
|
||||
var child = log.child();
|
||||
});
|
||||
console.log(' - adding no fields: %dms per iteration', ms);
|
||||
|
||||
var ms = ben(1e5, function () {
|
||||
var child = log.child({a:1});
|
||||
var child = log.child({a:1});
|
||||
});
|
||||
console.log(' - adding one field: %dms per iteration', ms);
|
||||
|
||||
var ms = ben(1e5, function () {
|
||||
var child = log.child({a:1, b:2});
|
||||
var child = log.child({a:1, b:2});
|
||||
});
|
||||
console.log(' - adding two fields: %dms per iteration', ms);
|
||||
|
||||
function fooSerializer(obj) {
|
||||
return {bar: obj.bar};
|
||||
return {bar: obj.bar};
|
||||
}
|
||||
var ms = ben(1e5, function () {
|
||||
var child = log.child({
|
||||
a: 1,
|
||||
serializers: {foo: fooSerializer}
|
||||
});
|
||||
var child = log.child({
|
||||
a: 1,
|
||||
serializers: {foo: fooSerializer}
|
||||
});
|
||||
});
|
||||
console.log(' - adding serializer and one field: %dms per iteration', ms);
|
||||
|
||||
var ms = ben(1e5, function () {
|
||||
var child = log.child({
|
||||
a: 1,
|
||||
streams: [ {stream: process.stderr} ]
|
||||
});
|
||||
var child = log.child({
|
||||
a: 1,
|
||||
streams: [ {stream: process.stderr} ]
|
||||
});
|
||||
});
|
||||
console.log(' - adding a (stderr) stream and one field: %dms per iteration',
|
||||
ms);
|
||||
ms);
|
||||
|
||||
var ms = ben(1e6, function () {
|
||||
var child = log.child({}, true);
|
||||
var child = log.child({}, true);
|
||||
});
|
||||
console.log(' - [fast] adding no fields: %dms per iteration', ms);
|
||||
|
||||
var ms = ben(1e6, function () {
|
||||
var child = log.child({a:1}, true);
|
||||
var child = log.child({a:1}, true);
|
||||
});
|
||||
console.log(' - [fast] adding one field: %dms per iteration', ms);
|
||||
|
||||
var ms = ben(1e6, function () {
|
||||
var child = log.child({a:1, b:2}, true);
|
||||
var child = log.child({a:1, b:2}, true);
|
||||
});
|
||||
console.log(' - [fast] adding two fields: %dms per iteration', ms);
|
||||
|
|
|
@ -12,17 +12,17 @@ var records = [];
|
|||
function Collector() {
|
||||
}
|
||||
Collector.prototype.write = function (s) {
|
||||
//records.push(s);
|
||||
//records.push(s);
|
||||
}
|
||||
var collector = new Collector();
|
||||
|
||||
var log = new Logger({
|
||||
name: 'timeguard',
|
||||
src: true,
|
||||
stream: collector
|
||||
name: 'timeguard',
|
||||
src: true,
|
||||
stream: collector
|
||||
});
|
||||
|
||||
var ms = ben(1e5, function () {
|
||||
log.info('hi');
|
||||
log.info('hi');
|
||||
});
|
||||
console.log(' - log.info: %dms per iteration', ms);
|
||||
|
|
|
@ -12,26 +12,26 @@ var records = [];
|
|||
function Collector() {
|
||||
}
|
||||
Collector.prototype.write = function (s) {
|
||||
//records.push(s);
|
||||
//records.push(s);
|
||||
}
|
||||
var collector = new Collector();
|
||||
|
||||
var logwith = new Logger({
|
||||
name: 'with-src',
|
||||
src: true,
|
||||
stream: collector
|
||||
name: 'with-src',
|
||||
src: true,
|
||||
stream: collector
|
||||
});
|
||||
|
||||
var ms = ben(1e5, function () {
|
||||
logwith.info('hi');
|
||||
logwith.info('hi');
|
||||
});
|
||||
console.log(' - log.info with src: %dms per iteration', ms);
|
||||
|
||||
var logwithout = new Logger({
|
||||
name: 'without-src',
|
||||
stream: collector
|
||||
name: 'without-src',
|
||||
stream: collector
|
||||
});
|
||||
var ms = ben(1e5, function () {
|
||||
logwithout.info('hi');
|
||||
logwithout.info('hi');
|
||||
});
|
||||
console.log(' - log.info without src: %dms per iteration', ms);
|
||||
|
|
Loading…
Reference in a new issue