mirror of
https://github.com/pinojs/pino.git
synced 2025-12-08 20:36:13 +00:00
tests: test param lambdas, destructure t, switch to end always, tweaks
This commit is contained in:
parent
41734bfd88
commit
3c21d18fba
@ -5,7 +5,7 @@ const { onTerminatedSym, streamSym } = require('./symbols')
|
||||
function events (instance) {
|
||||
const stream = instance[streamSym]
|
||||
|
||||
if (stream instanceof SonicBoom === true) {
|
||||
if (stream instanceof SonicBoom) {
|
||||
if (stream.fd === -1) {
|
||||
stream.on('ready', register)
|
||||
} else {
|
||||
|
||||
@ -137,6 +137,7 @@ function getPrettyStream (opts, prettifier, dest) {
|
||||
}
|
||||
try {
|
||||
var prettyFactory = require('pino-pretty')
|
||||
prettyFactory.asMetaWrapper = asMetaWrapper
|
||||
return asMetaWrapper(prettyFactory(opts), dest)
|
||||
} catch (e) {
|
||||
throw Error('Missing `pino-pretty` module: `pino-pretty` must be installed separately')
|
||||
|
||||
@ -4,67 +4,58 @@ var test = require('tap').test
|
||||
var sink = require('./helper').sink
|
||||
var pino = require('../')
|
||||
|
||||
test('can add a custom level via constructor', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('can add a custom level via constructor', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'foo', levelVal: 35}, sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.msg, 'bar')
|
||||
cb()
|
||||
is(chunk.msg, 'bar')
|
||||
end()
|
||||
}))
|
||||
|
||||
t.is(typeof log.foo, 'function')
|
||||
is(typeof log.foo, 'function')
|
||||
log.foo('bar')
|
||||
})
|
||||
|
||||
test('can add a custom level to a prior instance', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('can add a custom level to a prior instance', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino(sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.msg, 'bar')
|
||||
is(chunk.msg, 'bar')
|
||||
end()
|
||||
}))
|
||||
|
||||
log.addLevel('foo2', 35)
|
||||
t.is(typeof log.foo2, 'function')
|
||||
is(typeof log.foo2, 'function')
|
||||
log.foo2('bar')
|
||||
})
|
||||
|
||||
test('custom level via constructor does not affect other instances', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('custom level via constructor does not affect other instances', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'foo3', levelVal: 36})
|
||||
var other = pino()
|
||||
t.is(typeof log.foo3, 'function')
|
||||
t.is(typeof other.foo3, 'undefined')
|
||||
is(typeof log.foo3, 'function')
|
||||
is(typeof other.foo3, 'undefined')
|
||||
end()
|
||||
})
|
||||
|
||||
test('custom level on one instance does not affect other instances', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('custom level on one instance does not affect other instances', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino()
|
||||
log.addLevel('foo4', 37)
|
||||
var other = pino()
|
||||
log.addLevel('foo5', 38)
|
||||
t.is(typeof other.foo4, 'undefined')
|
||||
t.is(typeof other.foo5, 'undefined')
|
||||
is(typeof other.foo4, 'undefined')
|
||||
is(typeof other.foo5, 'undefined')
|
||||
end()
|
||||
})
|
||||
|
||||
test('custom levels encompass higher levels', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('custom levels encompass higher levels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'foo', levelVal: 35}, sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.msg, 'bar')
|
||||
cb()
|
||||
is(chunk.msg, 'bar')
|
||||
end()
|
||||
}))
|
||||
|
||||
log.warn('bar')
|
||||
})
|
||||
|
||||
test('after the fact add level does not include lower levels', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('after the fact add level does not include lower levels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino(sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.msg, 'bar')
|
||||
cb()
|
||||
is(chunk.msg, 'bar')
|
||||
end()
|
||||
}))
|
||||
|
||||
log.addLevel('foo', 35)
|
||||
@ -73,12 +64,10 @@ test('after the fact add level does not include lower levels', function (t) {
|
||||
log.foo('bar')
|
||||
})
|
||||
|
||||
test('after the fact add of a lower level does not include it', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('after the fact add of a lower level does not include it', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino(sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.msg, 'bar')
|
||||
cb()
|
||||
is(chunk.msg, 'bar')
|
||||
end()
|
||||
}))
|
||||
|
||||
log.level = 'info'
|
||||
@ -87,68 +76,64 @@ test('after the fact add of a lower level does not include it', function (t) {
|
||||
log.foo('nope')
|
||||
})
|
||||
|
||||
test('children can be set to custom level', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('children can be set to custom level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({level: 'foo', levelVal: 35}, sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.msg, 'bar')
|
||||
t.is(chunk.child, 'yes')
|
||||
cb()
|
||||
is(chunk.msg, 'bar')
|
||||
is(chunk.child, 'yes')
|
||||
end()
|
||||
}))
|
||||
var child = parent.child({child: 'yes'})
|
||||
child.foo('bar')
|
||||
})
|
||||
|
||||
test('custom levels exists on children', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('custom levels exists on children', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({}, sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.msg, 'bar')
|
||||
t.is(chunk.child, 'yes')
|
||||
cb()
|
||||
is(chunk.msg, 'bar')
|
||||
is(chunk.child, 'yes')
|
||||
end()
|
||||
}))
|
||||
parent.addLevel('foo', 35)
|
||||
var child = parent.child({child: 'yes'})
|
||||
child.foo('bar')
|
||||
})
|
||||
|
||||
test('rejects already known labels', function (t) {
|
||||
t.plan(1)
|
||||
test('rejects already known labels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'info', levelVal: 900})
|
||||
t.is(log.levelVal, 30)
|
||||
is(log.levelVal, 30)
|
||||
end()
|
||||
})
|
||||
|
||||
test('reject already known values', function (t) {
|
||||
t.plan(1)
|
||||
test('reject already known values', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
try {
|
||||
pino({level: 'foo', levelVal: 30})
|
||||
} catch (e) {
|
||||
t.is(e.message.indexOf('level value') > -1, true)
|
||||
is(e.message.indexOf('level value') > -1, true)
|
||||
} finally {
|
||||
end()
|
||||
}
|
||||
})
|
||||
|
||||
test('reject values of Infinity', function (t) {
|
||||
t.plan(1)
|
||||
t.throws(function () {
|
||||
test('reject values of Infinity', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(function () {
|
||||
pino({level: 'foo', levelVal: Infinity})
|
||||
}, /.*level value is already used.*/)
|
||||
end()
|
||||
})
|
||||
|
||||
test('level numbers are logged correctly after level change', function (t) {
|
||||
t.plan(1)
|
||||
test('level numbers are logged correctly after level change', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'foo', levelVal: 25}, sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.level, 25)
|
||||
is(chunk.level, 25)
|
||||
end()
|
||||
}))
|
||||
log.level = 'debug'
|
||||
log.foo('bar')
|
||||
})
|
||||
|
||||
test('levels state is not shared between instances', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('levels state is not shared between instances', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance1 = pino({level: 'foo', levelVal: 35})
|
||||
t.is(typeof instance1.foo, 'function')
|
||||
is(typeof instance1.foo, 'function')
|
||||
|
||||
var instance2 = pino()
|
||||
t.is(instance2.hasOwnProperty('foo'), false)
|
||||
is(instance2.hasOwnProperty('foo'), false)
|
||||
end()
|
||||
})
|
||||
|
||||
@ -10,54 +10,54 @@ var check = require('./helper').check
|
||||
var pid = process.pid
|
||||
var hostname = os.hostname()
|
||||
|
||||
test('pino version is exposed', function (t) {
|
||||
t.plan(2)
|
||||
test('pino version is exposed', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino()
|
||||
t.ok(instance.pino)
|
||||
t.is(instance.pino, require('../package.json').version)
|
||||
ok(instance.pino)
|
||||
is(instance.pino, require('../package.json').version)
|
||||
end()
|
||||
})
|
||||
|
||||
test('child exposes pino version', function (t) {
|
||||
t.plan(1)
|
||||
test('child exposes pino version', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var child = pino().child({foo: 'bar'})
|
||||
t.ok(child.pino)
|
||||
ok(child.pino)
|
||||
end()
|
||||
})
|
||||
|
||||
function levelTest (name, level) {
|
||||
test(name + ' logs as ' + level, function (t) {
|
||||
t.plan(2)
|
||||
test(name + ' logs as ' + level, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
check(t, chunk, level, 'hello world')
|
||||
check(is, chunk, level, 'hello world')
|
||||
end()
|
||||
cb()
|
||||
}))
|
||||
|
||||
instance.level = name
|
||||
instance[name]('hello world')
|
||||
})
|
||||
|
||||
test('passing objects at level ' + name, function (t) {
|
||||
t.plan(2)
|
||||
test('passing objects at level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
hello: 'world',
|
||||
v: 1
|
||||
})
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.level = name
|
||||
instance[name]({ hello: 'world' })
|
||||
})
|
||||
|
||||
test('passing an object and a string at level ' + name, function (t) {
|
||||
t.plan(2)
|
||||
test('passing an object and a string at level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -65,33 +65,33 @@ function levelTest (name, level) {
|
||||
hello: 'world',
|
||||
v: 1
|
||||
})
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.level = name
|
||||
instance[name]({ hello: 'world' }, 'a string')
|
||||
})
|
||||
|
||||
test('formatting logs as ' + name, function (t) {
|
||||
t.plan(2)
|
||||
test('formatting logs as ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
check(t, chunk, level, 'hello 42')
|
||||
check(is, chunk, level, 'hello 42')
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.level = name
|
||||
instance[name]('hello %d', 42)
|
||||
})
|
||||
|
||||
test('passing error with a serializer at level ' + name, function (t) {
|
||||
t.plan(2)
|
||||
test('passing error with a serializer at level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = new Error('myerror')
|
||||
var instance = pino({
|
||||
serializers: {
|
||||
err: pino.stdSerializers.err
|
||||
}
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -102,19 +102,18 @@ function levelTest (name, level) {
|
||||
},
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.level = name
|
||||
instance[name]({ err: err })
|
||||
})
|
||||
|
||||
test('child logger for level ' + name, function (t) {
|
||||
t.plan(2)
|
||||
test('child logger for level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -122,6 +121,7 @@ function levelTest (name, level) {
|
||||
hello: 'world',
|
||||
v: 1
|
||||
})
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.level = name
|
||||
@ -139,59 +139,50 @@ levelTest('info', 30)
|
||||
levelTest('debug', 20)
|
||||
levelTest('trace', 10)
|
||||
|
||||
test('serializers can return undefined to strip field', function (t) {
|
||||
t.plan(1)
|
||||
test('serializers can return undefined to strip field', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
serializers: {
|
||||
test: function (o) { return undefined }
|
||||
}
|
||||
}, sink(function (obj, enc, cb) {
|
||||
t.notOk('test' in obj)
|
||||
cb()
|
||||
is('test' in obj, false)
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info({ test: 'sensitive info' })
|
||||
})
|
||||
|
||||
test('does not explode with a circular ref', function (t) {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
// nothing to check
|
||||
cb()
|
||||
}))
|
||||
test('does not explode with a circular ref', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(() => {}))
|
||||
var b = {}
|
||||
var a = {
|
||||
hello: b
|
||||
}
|
||||
b.a = a // circular ref
|
||||
instance.info(a)
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
|
||||
test('explode with a circular ref with safe = false', function (t) {
|
||||
var instance = pino({ safe: false }, sink(function (chunk, enc, cb) {
|
||||
// nothing to check
|
||||
cb()
|
||||
}))
|
||||
test('explode with a circular ref with safe = false', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({ safe: false }, sink())
|
||||
var b = {}
|
||||
var a = {
|
||||
hello: b
|
||||
}
|
||||
b.a = a // circular ref
|
||||
t.throws(function () {
|
||||
throws(function () {
|
||||
instance.info(a)
|
||||
})
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
|
||||
test('set the name', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('set the name', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
name: 'hello'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 60,
|
||||
@ -199,68 +190,62 @@ test('set the name', function (t) {
|
||||
msg: 'this is fatal',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal('this is fatal')
|
||||
})
|
||||
|
||||
test('set the messageKey', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('set the messageKey', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var message = 'hello world'
|
||||
var messageKey = 'fooMessage'
|
||||
var instance = pino({
|
||||
messageKey: messageKey
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
fooMessage: message,
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info(message)
|
||||
})
|
||||
|
||||
test('set undefined properties', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('set undefined properties', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
hello: 'world',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info({ hello: 'world', property: undefined })
|
||||
})
|
||||
|
||||
test('set properties defined in the prototype chain', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('set properties defined in the prototype chain', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
hello: 'world',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
function MyObject () {
|
||||
@ -272,69 +257,55 @@ test('set properties defined in the prototype chain', function (t) {
|
||||
instance.info(new MyObject())
|
||||
})
|
||||
|
||||
test('set the base', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('set the base', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
base: {
|
||||
a: 'b'
|
||||
}
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
a: 'b',
|
||||
level: 60,
|
||||
msg: 'this is fatal',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal('this is fatal')
|
||||
})
|
||||
|
||||
test('set the base to null', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('set the base to null', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
base: null
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
level: 60,
|
||||
msg: 'this is fatal',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal('this is fatal')
|
||||
})
|
||||
|
||||
test('throw if creating child without bindings', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = pino(
|
||||
sink(function (chunk, enc, cb) {
|
||||
t.ok(Date.parse(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
t.throws(function () {
|
||||
instance.child()
|
||||
})
|
||||
test('throw if creating child without bindings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink())
|
||||
throws(() => instance.child())
|
||||
end()
|
||||
})
|
||||
|
||||
test('correctly escape msg strings / 1', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('correctly escape msg strings / 1', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
name: 'hello'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 60,
|
||||
@ -342,20 +313,18 @@ test('correctly escape msg strings / 1', function (t) {
|
||||
msg: 'this contains "',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal('this contains "')
|
||||
})
|
||||
|
||||
test('correctly escape msg strings / 2', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('correctly escape msg strings / 2', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
name: 'hello'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 60,
|
||||
@ -363,34 +332,33 @@ test('correctly escape msg strings / 2', function (t) {
|
||||
msg: '" this contains',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal('" this contains')
|
||||
})
|
||||
|
||||
// https://github.com/pinojs/pino/issues/139
|
||||
test('object and format string', function (t) {
|
||||
test('object and format string', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
msg: 'foo bar',
|
||||
v: 1
|
||||
})
|
||||
t.end()
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info({}, 'foo %s', 'bar')
|
||||
})
|
||||
|
||||
test('object and format string property', function (t) {
|
||||
test('object and format string property', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -398,36 +366,31 @@ test('object and format string property', function (t) {
|
||||
answer: 42,
|
||||
v: 1
|
||||
})
|
||||
t.end()
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info({ answer: 42 }, 'foo %s', 'bar')
|
||||
})
|
||||
|
||||
test('correctly strip undefined when returned from toJSON', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('correctly strip undefined when returned from toJSON', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
test: 'this'
|
||||
}, sink(function (obj, enc, cb) {
|
||||
t.notOk('test' in obj)
|
||||
cb()
|
||||
is('test' in obj, false)
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal({test: {toJSON: function () { return undefined }}})
|
||||
})
|
||||
|
||||
test('correctly support node v4+ stderr', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('correctly support node v4+ stderr', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
// stderr inherits from Stream, rather than Writable
|
||||
var dest = {
|
||||
writable: true,
|
||||
write: function (chunk) {
|
||||
chunk = JSON.parse(chunk)
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 60,
|
||||
@ -440,29 +403,29 @@ test('correctly support node v4+ stderr', function (t) {
|
||||
var instance = pino(dest)
|
||||
|
||||
instance.fatal('a message')
|
||||
end()
|
||||
})
|
||||
|
||||
test('normalize number to string', function (t) {
|
||||
test('normalize number to string', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
msg: '1',
|
||||
v: 1
|
||||
})
|
||||
t.end()
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info(1)
|
||||
})
|
||||
|
||||
test('normalize number to string with an object', function (t) {
|
||||
test('normalize number to string with an object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -470,25 +433,23 @@ test('normalize number to string with an object', function (t) {
|
||||
answer: 42,
|
||||
v: 1
|
||||
})
|
||||
t.end()
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info({ answer: 42 }, 1)
|
||||
})
|
||||
|
||||
test('handles objects with null prototype', function (t) {
|
||||
test('handles objects with null prototype', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
test: 'test',
|
||||
v: 1
|
||||
})
|
||||
t.end()
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
var o = Object.create(null)
|
||||
o.test = 'test'
|
||||
@ -496,19 +457,17 @@ test('handles objects with null prototype', function (t) {
|
||||
})
|
||||
|
||||
// https://github.com/pinojs/pino/issues/222
|
||||
test('children with same names render in correct order', function (t) {
|
||||
t.plan(1)
|
||||
test('children with same names render in correct order', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var root = pino(sink(function (chunk, enc, cb) {
|
||||
t.is(chunk.a, 3, 'last logged object takes precedence')
|
||||
cb()
|
||||
is(chunk.a, 3, 'last logged object takes precedence')
|
||||
end()
|
||||
}))
|
||||
|
||||
root.child({a: 1}).child({a: 2}).info({a: 3})
|
||||
})
|
||||
|
||||
// https://github.com/pinojs/pino/pull/251 - use this.stringify
|
||||
test('when safe is true it should ONLY use `fast-safe-stringify`', function (t) {
|
||||
t.plan(2)
|
||||
test('when safe is true it should ONLY use `fast-safe-stringify`', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var safeStates = [true, false]
|
||||
var isFastSafeStringifyCalled = null
|
||||
var mockedPino = proxyquire('../', {
|
||||
@ -519,11 +478,9 @@ test('when safe is true it should ONLY use `fast-safe-stringify`', function (t)
|
||||
})
|
||||
safeStates.forEach(function (safeState) {
|
||||
isFastSafeStringifyCalled = false
|
||||
var instance = mockedPino({ safe: safeState }, sink(function (chunk, enc, cb) {
|
||||
cb()
|
||||
}))
|
||||
var instance = mockedPino({ safe: safeState }, sink())
|
||||
instance.info({ hello: 'world' })
|
||||
t.equal(isFastSafeStringifyCalled, safeState)
|
||||
is(isFastSafeStringifyCalled, safeState)
|
||||
})
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
|
||||
@ -2,8 +2,7 @@
|
||||
var test = require('tape')
|
||||
var pino = require('../browser')
|
||||
|
||||
test('set the level by string', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level by string', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [
|
||||
{
|
||||
level: 50,
|
||||
@ -17,7 +16,7 @@ test('set the level by string', function (t) {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (actual) {
|
||||
checkLogObjects(t, actual, expected.shift())
|
||||
checkLogObjects(is, same, actual, expected.shift())
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -26,11 +25,11 @@ test('set the level by string', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('set the level by string. init with silent', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level by string. init with silent', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [
|
||||
{
|
||||
level: 50,
|
||||
@ -45,7 +44,7 @@ test('set the level by string. init with silent', function (t) {
|
||||
level: 'silent',
|
||||
browser: {
|
||||
write: function (actual) {
|
||||
checkLogObjects(t, actual, expected.shift())
|
||||
checkLogObjects(is, same, actual, expected.shift())
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -54,11 +53,11 @@ test('set the level by string. init with silent', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('set the level by string. init with silent and transmit', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level by string. init with silent and transmit', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [
|
||||
{
|
||||
level: 50,
|
||||
@ -73,7 +72,7 @@ test('set the level by string. init with silent and transmit', function (t) {
|
||||
level: 'silent',
|
||||
browser: {
|
||||
write: function (actual) {
|
||||
checkLogObjects(t, actual, expected.shift())
|
||||
checkLogObjects(is, same, actual, expected.shift())
|
||||
}
|
||||
},
|
||||
transmit: {
|
||||
@ -86,11 +85,11 @@ test('set the level by string. init with silent and transmit', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('set the level via constructor', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level via constructor', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [
|
||||
{
|
||||
level: 50,
|
||||
@ -105,7 +104,7 @@ test('set the level via constructor', function (t) {
|
||||
level: 'error',
|
||||
browser: {
|
||||
write: function (actual) {
|
||||
checkLogObjects(t, actual, expected.shift())
|
||||
checkLogObjects(is, same, actual, expected.shift())
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -113,47 +112,48 @@ test('set the level via constructor', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('the wrong level throws', function (t) {
|
||||
t.plan(1)
|
||||
test('the wrong level throws', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino()
|
||||
t.throws(function () {
|
||||
throws(function () {
|
||||
instance.level = 'kaboom'
|
||||
})
|
||||
end()
|
||||
})
|
||||
|
||||
test('the wrong level by number throws', function (t) {
|
||||
t.plan(1)
|
||||
test('the wrong level by number throws', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino()
|
||||
t.throws(function () {
|
||||
throws(function () {
|
||||
instance.levelVal = 55
|
||||
})
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes level string mappings', function (t) {
|
||||
t.plan(1)
|
||||
t.equal(pino.levels.values.error, 50)
|
||||
test('exposes level string mappings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
is(pino.levels.values.error, 50)
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes level number mappings', function (t) {
|
||||
t.plan(1)
|
||||
t.equal(pino.levels.labels[50], 'error')
|
||||
test('exposes level number mappings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
is(pino.levels.labels[50], 'error')
|
||||
end()
|
||||
})
|
||||
|
||||
test('returns level integer', function (t) {
|
||||
t.plan(1)
|
||||
test('returns level integer', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({level: 'error'})
|
||||
t.equal(instance.levelVal, 50)
|
||||
is(instance.levelVal, 50)
|
||||
end()
|
||||
})
|
||||
|
||||
test('silent level via constructor', function (t) {
|
||||
test('silent level via constructor', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
level: 'silent',
|
||||
browser: {
|
||||
write: function (actual) {
|
||||
t.fail('no data should be logged')
|
||||
fail('no data should be logged')
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -161,14 +161,15 @@ test('silent level via constructor', function (t) {
|
||||
Object.keys(pino.levels.values).forEach(function (level) {
|
||||
instance[level]('hello world')
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('silent level by string', function (t) {
|
||||
test('silent level by string', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (actual) {
|
||||
t.fail('no data should be logged')
|
||||
fail('no data should be logged')
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -178,12 +179,12 @@ test('silent level by string', function (t) {
|
||||
Object.keys(pino.levels.values).forEach(function (level) {
|
||||
instance[level]('hello world')
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposed levels', function (t) {
|
||||
t.plan(1)
|
||||
t.deepEqual(Object.keys(pino.levels.values), [
|
||||
test('exposed levels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
same(Object.keys(pino.levels.values), [
|
||||
'fatal',
|
||||
'error',
|
||||
'warn',
|
||||
@ -191,11 +192,11 @@ test('exposed levels', function (t) {
|
||||
'debug',
|
||||
'trace'
|
||||
])
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposed labels', function (t) {
|
||||
t.plan(1)
|
||||
t.deepEqual(Object.keys(pino.levels.labels), [
|
||||
test('exposed labels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
same(Object.keys(pino.levels.labels), [
|
||||
'10',
|
||||
'20',
|
||||
'30',
|
||||
@ -203,15 +204,16 @@ test('exposed labels', function (t) {
|
||||
'50',
|
||||
'60'
|
||||
])
|
||||
end()
|
||||
})
|
||||
|
||||
function checkLogObjects (t, actual, expected) {
|
||||
t.ok(actual.time <= Date.now(), 'time is greater than Date.now()')
|
||||
function checkLogObjects (is, same, actual, expected) {
|
||||
is(actual.time <= Date.now(), true, 'time is greater than Date.now()')
|
||||
|
||||
var actualCopy = Object.assign({}, actual)
|
||||
var expectedCopy = Object.assign({}, expected)
|
||||
delete actualCopy.time
|
||||
delete expectedCopy.time
|
||||
|
||||
t.deepEqual(actualCopy, expectedCopy)
|
||||
same(actualCopy, expectedCopy)
|
||||
}
|
||||
|
||||
@ -14,33 +14,30 @@ var childSerializers = {
|
||||
test: function () { return 'child' }
|
||||
}
|
||||
|
||||
test('serializers override values', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('serializers override values', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({ serializers: parentSerializers,
|
||||
browser: { serialize: true,
|
||||
write: function (o) {
|
||||
t.is(o.test, 'parent')
|
||||
is(o.test, 'parent')
|
||||
end()
|
||||
}}})
|
||||
|
||||
parent.fatal({test: 'test'})
|
||||
})
|
||||
|
||||
test('without the serialize option, serializers do not override values', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('without the serialize option, serializers do not override values', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({ serializers: parentSerializers,
|
||||
browser: {
|
||||
write: function (o) {
|
||||
t.is(o.test, 'test')
|
||||
is(o.test, 'test')
|
||||
end()
|
||||
}}})
|
||||
|
||||
parent.fatal({test: 'test'})
|
||||
})
|
||||
|
||||
if (process.title !== 'browser') {
|
||||
test('if serialize option is true, standard error serializer is auto enabled', function (t) {
|
||||
t.plan(1)
|
||||
test('if serialize option is true, standard error serializer is auto enabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Error('test')
|
||||
err.code = 'test'
|
||||
err.type = 'Error' // get that cov
|
||||
@ -48,7 +45,7 @@ if (process.title !== 'browser') {
|
||||
|
||||
var consoleError = console.error
|
||||
console.error = function (err) {
|
||||
t.deepEqual(err, expect)
|
||||
same(err, expect)
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -58,17 +55,17 @@ if (process.title !== 'browser') {
|
||||
console.error = consoleError
|
||||
|
||||
logger.fatal(err)
|
||||
end()
|
||||
})
|
||||
|
||||
test('if serialize option is array, standard error serializer is auto enabled', function (t) {
|
||||
t.plan(1)
|
||||
test('if serialize option is array, standard error serializer is auto enabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Error('test')
|
||||
err.code = 'test'
|
||||
var expect = pino.stdSerializers.err(err)
|
||||
|
||||
var consoleError = console.error
|
||||
console.error = function (err) {
|
||||
t.deepEqual(err, expect)
|
||||
same(err, expect)
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -78,17 +75,17 @@ if (process.title !== 'browser') {
|
||||
console.error = consoleError
|
||||
|
||||
logger.fatal(err)
|
||||
end()
|
||||
})
|
||||
|
||||
test('if serialize option is array containing !stdSerializers.err, standard error serializer is disabled', function (t) {
|
||||
t.plan(1)
|
||||
test('if serialize option is array containing !stdSerializers.err, standard error serializer is disabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Error('test')
|
||||
err.code = 'test'
|
||||
var expect = err
|
||||
|
||||
var consoleError = console.error
|
||||
console.error = function (err) {
|
||||
t.is(err, expect)
|
||||
is(err, expect)
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -98,15 +95,15 @@ if (process.title !== 'browser') {
|
||||
console.error = consoleError
|
||||
|
||||
logger.fatal(err)
|
||||
end()
|
||||
})
|
||||
|
||||
test('in browser, serializers apply to all objects', function (t) {
|
||||
t.plan(3)
|
||||
test('in browser, serializers apply to all objects', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var consoleError = console.error
|
||||
console.error = function (test, test2, test3, test4, test5) {
|
||||
t.is(test.key, 'serialized')
|
||||
t.is(test2.key2, 'serialized2')
|
||||
t.is(test5.key3, 'serialized3')
|
||||
is(test.key, 'serialized')
|
||||
is(test2.key2, 'serialized2')
|
||||
is(test5.key3, 'serialized3')
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -121,15 +118,15 @@ if (process.title !== 'browser') {
|
||||
console.error = consoleError
|
||||
|
||||
logger.fatal({key: 'test'}, {key2: 'test'}, 'str should skip', [{foo: 'array should skip'}], {key3: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('serialize can be an array of selected serializers', function (t) {
|
||||
t.plan(3)
|
||||
test('serialize can be an array of selected serializers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var consoleError = console.error
|
||||
console.error = function (test, test2, test3, test4, test5) {
|
||||
t.is(test.key, 'test')
|
||||
t.is(test2.key2, 'serialized2')
|
||||
t.is(test5.key3, 'test')
|
||||
is(test.key, 'test')
|
||||
is(test2.key2, 'serialized2')
|
||||
is(test5.key3, 'test')
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -144,15 +141,15 @@ if (process.title !== 'browser') {
|
||||
console.error = consoleError
|
||||
|
||||
logger.fatal({key: 'test'}, {key2: 'test'}, 'str should skip', [{foo: 'array should skip'}], {key3: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('serialize filter applies to child loggers', function (t) {
|
||||
t.plan(3)
|
||||
test('serialize filter applies to child loggers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var consoleError = console.error
|
||||
console.error = function (binding, test, test2, test3, test4, test5) {
|
||||
t.is(test.key, 'test')
|
||||
t.is(test2.key2, 'serialized2')
|
||||
t.is(test5.key3, 'test')
|
||||
is(test.key, 'test')
|
||||
is(test2.key2, 'serialized2')
|
||||
is(test5.key3, 'test')
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -167,13 +164,13 @@ if (process.title !== 'browser') {
|
||||
key2: function () { return 'serialized2' },
|
||||
key3: function () { return 'serialized3' }
|
||||
}}).fatal({key: 'test'}, {key2: 'test'}, 'str should skip', [{foo: 'array should skip'}], {key3: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('parent serializers apply to child bindings', function (t) {
|
||||
t.plan(1)
|
||||
test('parent serializers apply to child bindings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var consoleError = console.error
|
||||
console.error = function (binding) {
|
||||
t.is(binding.key, 'serialized')
|
||||
is(binding.key, 'serialized')
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -186,13 +183,13 @@ if (process.title !== 'browser') {
|
||||
console.error = consoleError
|
||||
|
||||
logger.child({key: 'test'}).fatal({test: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('child serializers apply to child bindings', function (t) {
|
||||
t.plan(1)
|
||||
test('child serializers apply to child bindings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var consoleError = console.error
|
||||
console.error = function (binding) {
|
||||
t.is(binding.key, 'serialized')
|
||||
is(binding.key, 'serialized')
|
||||
}
|
||||
|
||||
var logger = fresh('../browser', require)({
|
||||
@ -205,19 +202,21 @@ if (process.title !== 'browser') {
|
||||
serializers: {
|
||||
key: function () { return 'serialized' }
|
||||
}}).fatal({test: 'test'})
|
||||
end()
|
||||
})
|
||||
}
|
||||
|
||||
test('child does not overwrite parent serializers', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('child does not overwrite parent serializers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var c = 0
|
||||
var parent = pino({ serializers: parentSerializers,
|
||||
browser: { serialize: true,
|
||||
write: function (o) {
|
||||
c++
|
||||
if (c === 1) t.is(o.test, 'parent')
|
||||
if (c === 2) t.is(o.test, 'child')
|
||||
if (c === 1) is(o.test, 'parent')
|
||||
if (c === 2) {
|
||||
is(o.test, 'child')
|
||||
end()
|
||||
}
|
||||
}}})
|
||||
var child = parent.child({ serializers: childSerializers })
|
||||
|
||||
@ -225,52 +224,48 @@ test('child does not overwrite parent serializers', function (t) {
|
||||
child.fatal({test: 'test'})
|
||||
})
|
||||
|
||||
test('children inherit parent serializers', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('children inherit parent serializers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({ serializers: parentSerializers,
|
||||
browser: { serialize: true,
|
||||
write: function (o) {
|
||||
t.is(o.test, 'parent')
|
||||
is(o.test, 'parent')
|
||||
}}})
|
||||
|
||||
var child = parent.child({a: 'property'})
|
||||
child.fatal({test: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('children serializers get called', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('children serializers get called', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({
|
||||
test: 'this',
|
||||
browser: { serialize: true,
|
||||
write: function (o) {
|
||||
t.is(o.test, 'child')
|
||||
is(o.test, 'child')
|
||||
}}})
|
||||
|
||||
var child = parent.child({ 'a': 'property', serializers: childSerializers })
|
||||
|
||||
child.fatal({test: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('children serializers get called when inherited from parent', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('children serializers get called when inherited from parent', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({
|
||||
test: 'this',
|
||||
serializers: parentSerializers,
|
||||
browser: { serialize: true,
|
||||
write: function (o) {
|
||||
t.is(o.test, 'pass')
|
||||
is(o.test, 'pass')
|
||||
}}})
|
||||
|
||||
var child = parent.child({serializers: {test: function () { return 'pass' }}})
|
||||
|
||||
child.fatal({test: 'fail'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('non overriden serializers are available in the children', function (t) {
|
||||
t.plan(4)
|
||||
test('non overriden serializers are available in the children', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var pSerializers = {
|
||||
onlyParent: function () { return 'parent' },
|
||||
shared: function () { return 'parent' }
|
||||
@ -287,10 +282,10 @@ test('non overriden serializers are available in the children', function (t) {
|
||||
browser: { serialize: true,
|
||||
write: function (o) {
|
||||
c++
|
||||
if (c === 1) t.is(o.shared, 'child')
|
||||
if (c === 2) t.is(o.onlyParent, 'parent')
|
||||
if (c === 3) t.is(o.onlyChild, 'child')
|
||||
if (c === 4) t.is(o.onlyChild, 'test')
|
||||
if (c === 1) is(o.shared, 'child')
|
||||
if (c === 2) is(o.onlyParent, 'parent')
|
||||
if (c === 3) is(o.onlyChild, 'child')
|
||||
if (c === 4) is(o.onlyChild, 'test')
|
||||
}}})
|
||||
|
||||
var child = parent.child({ serializers: cSerializers })
|
||||
@ -299,4 +294,5 @@ test('non overriden serializers are available in the children', function (t) {
|
||||
child.fatal({onlyParent: 'test'})
|
||||
child.fatal({onlyChild: 'test'})
|
||||
parent.fatal({onlyChild: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
@ -4,20 +4,19 @@ var pino = require('../browser')
|
||||
|
||||
function noop () {}
|
||||
|
||||
test('throws if transmit object does not have send function', function (t) {
|
||||
t.throws(function () {
|
||||
test('throws if transmit object does not have send function', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(function () {
|
||||
pino({browser: {transmit: {}}})
|
||||
})
|
||||
|
||||
t.throws(function () {
|
||||
throws(function () {
|
||||
pino({browser: {transmit: {send: 'not a func'}}})
|
||||
})
|
||||
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
|
||||
test('calls send function after write', function (t) {
|
||||
t.plan(1)
|
||||
test('calls send function after write', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var c = 0
|
||||
var logger = pino({
|
||||
browser: {
|
||||
@ -26,52 +25,52 @@ test('calls send function after write', function (t) {
|
||||
},
|
||||
transmit: {
|
||||
send: function () {
|
||||
t.is(c, 1)
|
||||
is(c, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.fatal({test: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('passes send function the logged level', function (t) {
|
||||
t.plan(1)
|
||||
test('passes send function the logged level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino({
|
||||
browser: {
|
||||
write: function (o) {
|
||||
},
|
||||
transmit: {
|
||||
send: function (level) {
|
||||
t.is(level, 'fatal')
|
||||
is(level, 'fatal')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.fatal({test: 'test'})
|
||||
end()
|
||||
})
|
||||
|
||||
test('passes send function messages in logEvent object', function (t) {
|
||||
t.plan(2)
|
||||
test('passes send function messages in logEvent object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino({
|
||||
browser: {
|
||||
write: noop,
|
||||
transmit: {
|
||||
send: function (level, logEvent) {
|
||||
var messages = logEvent.messages
|
||||
t.same(messages[0], {test: 'test'})
|
||||
t.is(messages[1], 'another test')
|
||||
same(messages[0], {test: 'test'})
|
||||
is(messages[1], 'another test')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.fatal({test: 'test'}, 'another test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('supplies a timestamp (ts) in logEvent object which is exactly the same as the `time` property in asObject mode', function (t) {
|
||||
t.plan(1)
|
||||
test('supplies a timestamp (ts) in logEvent object which is exactly the same as the `time` property in asObject mode', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected
|
||||
var logger = pino({
|
||||
browser: {
|
||||
@ -81,17 +80,17 @@ test('supplies a timestamp (ts) in logEvent object which is exactly the same as
|
||||
},
|
||||
transmit: {
|
||||
send: function (level, logEvent) {
|
||||
t.is(logEvent.ts, expected)
|
||||
is(logEvent.ts, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.fatal('test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('passes send function child bindings via logEvent object', function (t) {
|
||||
t.plan(4)
|
||||
test('passes send function child bindings via logEvent object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino({
|
||||
browser: {
|
||||
write: noop,
|
||||
@ -99,10 +98,10 @@ test('passes send function child bindings via logEvent object', function (t) {
|
||||
send: function (level, logEvent) {
|
||||
var messages = logEvent.messages
|
||||
var bindings = logEvent.bindings
|
||||
t.same(bindings[0], {first: 'binding'})
|
||||
t.same(bindings[1], {second: 'binding2'})
|
||||
t.same(messages[0], {test: 'test'})
|
||||
t.is(messages[1], 'another test')
|
||||
same(bindings[0], {first: 'binding'})
|
||||
same(bindings[1], {second: 'binding2'})
|
||||
same(messages[0], {test: 'test'})
|
||||
is(messages[1], 'another test')
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,10 +111,10 @@ test('passes send function child bindings via logEvent object', function (t) {
|
||||
.child({first: 'binding'})
|
||||
.child({second: 'binding2'})
|
||||
.fatal({test: 'test'}, 'another test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('passes send function level:{label, value} via logEvent object', function (t) {
|
||||
t.plan(2)
|
||||
test('passes send function level:{label, value} via logEvent object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino({
|
||||
browser: {
|
||||
write: noop,
|
||||
@ -124,18 +123,18 @@ test('passes send function level:{label, value} via logEvent object', function (
|
||||
var label = logEvent.level.label
|
||||
var value = logEvent.level.value
|
||||
|
||||
t.is(label, 'fatal')
|
||||
t.is(value, 60)
|
||||
is(label, 'fatal')
|
||||
is(value, 60)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.fatal({test: 'test'}, 'another test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('calls send function according to transmit.level', function (t) {
|
||||
t.plan(2)
|
||||
test('calls send function according to transmit.level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var c = 0
|
||||
var logger = pino({
|
||||
browser: {
|
||||
@ -144,8 +143,8 @@ test('calls send function according to transmit.level', function (t) {
|
||||
level: 'error',
|
||||
send: function (level) {
|
||||
c++
|
||||
if (c === 1) t.is(level, 'error')
|
||||
if (c === 2) t.is(level, 'fatal')
|
||||
if (c === 1) is(level, 'error')
|
||||
if (c === 2) is(level, 'fatal')
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -153,10 +152,10 @@ test('calls send function according to transmit.level', function (t) {
|
||||
logger.warn('ignored')
|
||||
logger.error('test')
|
||||
logger.fatal('test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('transmit.level defaults to logger level', function (t) {
|
||||
t.plan(2)
|
||||
test('transmit.level defaults to logger level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var c = 0
|
||||
var logger = pino({
|
||||
level: 'error',
|
||||
@ -165,8 +164,8 @@ test('transmit.level defaults to logger level', function (t) {
|
||||
transmit: {
|
||||
send: function (level) {
|
||||
c++
|
||||
if (c === 1) t.is(level, 'error')
|
||||
if (c === 2) t.is(level, 'fatal')
|
||||
if (c === 1) is(level, 'error')
|
||||
if (c === 2) is(level, 'fatal')
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,10 +173,10 @@ test('transmit.level defaults to logger level', function (t) {
|
||||
logger.warn('ignored')
|
||||
logger.error('test')
|
||||
logger.fatal('test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('transmit.level is effective even if lower than logger level', function (t) {
|
||||
t.plan(3)
|
||||
test('transmit.level is effective even if lower than logger level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var c = 0
|
||||
var logger = pino({
|
||||
level: 'error',
|
||||
@ -187,9 +186,9 @@ test('transmit.level is effective even if lower than logger level', function (t)
|
||||
level: 'info',
|
||||
send: function (level) {
|
||||
c++
|
||||
if (c === 1) t.is(level, 'warn')
|
||||
if (c === 2) t.is(level, 'error')
|
||||
if (c === 3) t.is(level, 'fatal')
|
||||
if (c === 1) is(level, 'warn')
|
||||
if (c === 2) is(level, 'error')
|
||||
if (c === 3) is(level, 'fatal')
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,10 +196,10 @@ test('transmit.level is effective even if lower than logger level', function (t)
|
||||
logger.warn('ignored')
|
||||
logger.error('test')
|
||||
logger.fatal('test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('applies all serializers to messages and bindings (serialize:false - default)', function (t) {
|
||||
t.plan(4)
|
||||
test('applies all serializers to messages and bindings (serialize:false - default)', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino({
|
||||
serializers: {
|
||||
first: function () { return 'first' },
|
||||
@ -213,10 +212,10 @@ test('applies all serializers to messages and bindings (serialize:false - defaul
|
||||
send: function (level, logEvent) {
|
||||
var messages = logEvent.messages
|
||||
var bindings = logEvent.bindings
|
||||
t.same(bindings[0], {first: 'first'})
|
||||
t.same(bindings[1], {second: 'second'})
|
||||
t.same(messages[0], {test: 'serialize it'})
|
||||
t.is(messages[1].type, 'Error')
|
||||
same(bindings[0], {first: 'first'})
|
||||
same(bindings[1], {second: 'second'})
|
||||
same(messages[0], {test: 'serialize it'})
|
||||
is(messages[1].type, 'Error')
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,10 +225,10 @@ test('applies all serializers to messages and bindings (serialize:false - defaul
|
||||
.child({first: 'binding'})
|
||||
.child({second: 'binding2'})
|
||||
.fatal({test: 'test'}, Error())
|
||||
end()
|
||||
})
|
||||
|
||||
test('applies all serializers to messages and bindings (serialize:true)', function (t) {
|
||||
t.plan(4)
|
||||
test('applies all serializers to messages and bindings (serialize:true)', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino({
|
||||
serializers: {
|
||||
first: function () { return 'first' },
|
||||
@ -243,10 +242,10 @@ test('applies all serializers to messages and bindings (serialize:true)', functi
|
||||
send: function (level, logEvent) {
|
||||
var messages = logEvent.messages
|
||||
var bindings = logEvent.bindings
|
||||
t.same(bindings[0], {first: 'first'})
|
||||
t.same(bindings[1], {second: 'second'})
|
||||
t.same(messages[0], {test: 'serialize it'})
|
||||
t.is(messages[1].type, 'Error')
|
||||
same(bindings[0], {first: 'first'})
|
||||
same(bindings[1], {second: 'second'})
|
||||
same(messages[0], {test: 'serialize it'})
|
||||
is(messages[1].type, 'Error')
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,4 +255,5 @@ test('applies all serializers to messages and bindings (serialize:true)', functi
|
||||
.child({first: 'binding'})
|
||||
.child({second: 'binding2'})
|
||||
.fatal({test: 'test'}, Error())
|
||||
end()
|
||||
})
|
||||
|
||||
@ -10,11 +10,11 @@ levelTest('info')
|
||||
levelTest('debug')
|
||||
levelTest('trace')
|
||||
|
||||
test('silent level', function (t) {
|
||||
test('silent level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
level: 'silent',
|
||||
browser: {write: function (o) {
|
||||
t.fail()
|
||||
fail()
|
||||
}}
|
||||
})
|
||||
instance.info('test')
|
||||
@ -22,16 +22,16 @@ test('silent level', function (t) {
|
||||
child.info('msg-test')
|
||||
// use setTimeout because setImmediate isn't supported in most browsers
|
||||
setTimeout(function () {
|
||||
t.pass()
|
||||
t.end()
|
||||
pass()
|
||||
end()
|
||||
}, 0)
|
||||
})
|
||||
|
||||
test('enabled false', function (t) {
|
||||
test('enabled false', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
enabled: false,
|
||||
browser: {write: function (o) {
|
||||
t.fail()
|
||||
fail()
|
||||
}}
|
||||
})
|
||||
instance.info('test')
|
||||
@ -39,47 +39,43 @@ test('enabled false', function (t) {
|
||||
child.info('msg-test')
|
||||
// use setTimeout because setImmediate isn't supported in most browsers
|
||||
setTimeout(function () {
|
||||
t.pass()
|
||||
t.end()
|
||||
pass()
|
||||
end()
|
||||
}, 0)
|
||||
})
|
||||
|
||||
test('throw if creating child without bindings', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = pino()
|
||||
|
||||
t.throws(function () {
|
||||
instance.child()
|
||||
})
|
||||
test('throw if creating child without bindings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
const instance = pino()
|
||||
throws(() => instance.child())
|
||||
end()
|
||||
})
|
||||
|
||||
test('stubs write, flush and ee methods on instance', function (t) {
|
||||
test('stubs write, flush and ee methods on instance', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino()
|
||||
|
||||
t.ok(isFunc(instance.setMaxListeners))
|
||||
t.ok(isFunc(instance.getMaxListeners))
|
||||
t.ok(isFunc(instance.emit))
|
||||
t.ok(isFunc(instance.addListener))
|
||||
t.ok(isFunc(instance.on))
|
||||
t.ok(isFunc(instance.prependListener))
|
||||
t.ok(isFunc(instance.once))
|
||||
t.ok(isFunc(instance.prependOnceListener))
|
||||
t.ok(isFunc(instance.removeListener))
|
||||
t.ok(isFunc(instance.removeAllListeners))
|
||||
t.ok(isFunc(instance.listeners))
|
||||
t.ok(isFunc(instance.listenerCount))
|
||||
t.ok(isFunc(instance.eventNames))
|
||||
t.ok(isFunc(instance.write))
|
||||
t.ok(isFunc(instance.flush))
|
||||
ok(isFunc(instance.setMaxListeners))
|
||||
ok(isFunc(instance.getMaxListeners))
|
||||
ok(isFunc(instance.emit))
|
||||
ok(isFunc(instance.addListener))
|
||||
ok(isFunc(instance.on))
|
||||
ok(isFunc(instance.prependListener))
|
||||
ok(isFunc(instance.once))
|
||||
ok(isFunc(instance.prependOnceListener))
|
||||
ok(isFunc(instance.removeListener))
|
||||
ok(isFunc(instance.removeAllListeners))
|
||||
ok(isFunc(instance.listeners))
|
||||
ok(isFunc(instance.listenerCount))
|
||||
ok(isFunc(instance.eventNames))
|
||||
ok(isFunc(instance.write))
|
||||
ok(isFunc(instance.flush))
|
||||
|
||||
t.is(instance.on(), undefined)
|
||||
is(instance.on(), undefined)
|
||||
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes levels object', function (t) {
|
||||
t.deepEqual(pino.levels, {
|
||||
test('exposes levels object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
same(pino.levels, {
|
||||
values: {
|
||||
fatal: 60,
|
||||
error: 50,
|
||||
@ -97,31 +93,35 @@ test('exposes levels object', function (t) {
|
||||
'60': 'fatal'
|
||||
}
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes LOG_VERSION', function (t) {
|
||||
t.is(pino.LOG_VERSION, 1)
|
||||
t.end()
|
||||
test('exposes LOG_VERSION', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
is(pino.LOG_VERSION, 1)
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes faux stdSerializers', function (t) {
|
||||
t.ok(pino.stdSerializers)
|
||||
t.ok(pino.stdSerializers.req)
|
||||
t.ok(pino.stdSerializers.res)
|
||||
t.ok(pino.stdSerializers.err)
|
||||
t.deepEqual(pino.stdSerializers.req(), {})
|
||||
t.deepEqual(pino.stdSerializers.res(), {})
|
||||
t.end()
|
||||
test('exposes faux stdSerializers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
ok(pino.stdSerializers)
|
||||
ok(pino.stdSerializers.req)
|
||||
ok(pino.stdSerializers.res)
|
||||
ok(pino.stdSerializers.err)
|
||||
same(pino.stdSerializers.req(), {})
|
||||
same(pino.stdSerializers.res(), {})
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes err stdSerializer', function (t) {
|
||||
t.ok(pino.stdSerializers)
|
||||
t.ok(pino.stdSerializers.req)
|
||||
t.ok(pino.stdSerializers.res)
|
||||
t.ok(pino.stdSerializers.err)
|
||||
t.ok(pino.stdSerializers.err(Error()))
|
||||
t.end()
|
||||
test('exposes err stdSerializer', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
ok(pino.stdSerializers)
|
||||
ok(pino.stdSerializers.req)
|
||||
ok(pino.stdSerializers.res)
|
||||
ok(pino.stdSerializers.err)
|
||||
ok(pino.stdSerializers.err(Error()))
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
consoleMethodTest('error')
|
||||
@ -138,29 +138,28 @@ absentConsoleMethodTest('trace', 'log')
|
||||
|
||||
// do not run this with airtap
|
||||
if (process.title !== 'browser') {
|
||||
test('in absence of console, log methods become noops', function (t) {
|
||||
test('in absence of console, log methods become noops', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var console = global.console
|
||||
delete global.console
|
||||
var instance = fresh('../browser', require)()
|
||||
global.console = console
|
||||
t.ok(fnName(instance.log).match(/noop/))
|
||||
t.ok(fnName(instance.fatal).match(/noop/))
|
||||
t.ok(fnName(instance.error).match(/noop/))
|
||||
t.ok(fnName(instance.warn).match(/noop/))
|
||||
t.ok(fnName(instance.info).match(/noop/))
|
||||
t.ok(fnName(instance.debug).match(/noop/))
|
||||
t.ok(fnName(instance.trace).match(/noop/))
|
||||
t.end()
|
||||
ok(fnName(instance.log).match(/noop/))
|
||||
ok(fnName(instance.fatal).match(/noop/))
|
||||
ok(fnName(instance.error).match(/noop/))
|
||||
ok(fnName(instance.warn).match(/noop/))
|
||||
ok(fnName(instance.info).match(/noop/))
|
||||
ok(fnName(instance.debug).match(/noop/))
|
||||
ok(fnName(instance.trace).match(/noop/))
|
||||
end()
|
||||
})
|
||||
}
|
||||
|
||||
test('opts.browser.asObject logs pino-like object to console', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.asObject logs pino-like object to console', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var info = console.info
|
||||
console.info = function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.msg, 'test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.msg, 'test')
|
||||
ok(o.time)
|
||||
console.info = info
|
||||
}
|
||||
var instance = require('../browser')({
|
||||
@ -170,250 +169,255 @@ test('opts.browser.asObject logs pino-like object to console', function (t) {
|
||||
})
|
||||
|
||||
instance.info('test')
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write func log single string', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.write func log single string', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.msg, 'test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.msg, 'test')
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.info('test')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write func string joining', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.write func string joining', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.msg, 'test test2 test3')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.msg, 'test test2 test3')
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.info('test', 'test2', 'test3')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write func string object joining', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.write func string object joining', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.msg, 'test {"test":"test2"} {"test":"test3"}')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.msg, 'test {"test":"test2"} {"test":"test3"}')
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.info('test', {test: 'test2'}, {test: 'test3'})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write func string interpolation', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.write func string interpolation', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.msg, 'test2 test ({"test":"test3"})')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.msg, 'test2 test ({"test":"test3"})')
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.info('%s test (%j)', 'test2', {test: 'test3'})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write func number', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.write func number', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.msg, 1)
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.msg, 1)
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.info(1)
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write func log single object', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.write func log single object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.test, 'test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.test, 'test')
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.info({test: 'test'})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write obj writes to methods corresponding to level', function (t) {
|
||||
t.plan(3)
|
||||
test('opts.browser.write obj writes to methods corresponding to level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {
|
||||
write: {
|
||||
error: function (o) {
|
||||
t.is(o.level, 50)
|
||||
t.is(o.test, 'test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 50)
|
||||
is(o.test, 'test')
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.error({test: 'test'})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.asObject/write supports child loggers', function (t) {
|
||||
test('opts.browser.asObject/write supports child loggers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.test, 'test')
|
||||
t.is(o.msg, 'msg-test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.test, 'test')
|
||||
is(o.msg, 'msg-test')
|
||||
ok(o.time)
|
||||
}}
|
||||
})
|
||||
var child = instance.child({test: 'test'})
|
||||
child.info('msg-test')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.asObject/write supports child child loggers', function (t) {
|
||||
test('opts.browser.asObject/write supports child child loggers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.test, 'test')
|
||||
t.is(o.foo, 'bar')
|
||||
t.is(o.msg, 'msg-test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.test, 'test')
|
||||
is(o.foo, 'bar')
|
||||
is(o.msg, 'msg-test')
|
||||
ok(o.time)
|
||||
}}
|
||||
})
|
||||
var child = instance.child({test: 'test'}).child({foo: 'bar'})
|
||||
child.info('msg-test')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.asObject/write supports child child child loggers', function (t) {
|
||||
test('opts.browser.asObject/write supports child child child loggers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {write: function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.test, 'test')
|
||||
t.is(o.foo, 'bar')
|
||||
t.is(o.baz, 'bop')
|
||||
t.is(o.msg, 'msg-test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.test, 'test')
|
||||
is(o.foo, 'bar')
|
||||
is(o.baz, 'bop')
|
||||
is(o.msg, 'msg-test')
|
||||
ok(o.time)
|
||||
}}
|
||||
})
|
||||
var child = instance.child({test: 'test'}).child({foo: 'bar'}).child({baz: 'bop'})
|
||||
child.info('msg-test')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.asObject defensively mitigates naughty numbers', function (t) {
|
||||
test('opts.browser.asObject defensively mitigates naughty numbers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
browser: {asObject: true, write: function () {}}
|
||||
})
|
||||
var child = instance.child({test: 'test'})
|
||||
child._childLevel = -10
|
||||
child.info('test')
|
||||
t.pass() // if we reached here, there was no infinite loop, so, .. pass.
|
||||
t.end()
|
||||
pass() // if we reached here, there was no infinite loop, so, .. pass.
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('opts.browser.write obj falls back to console where a method is not supplied', function (t) {
|
||||
t.plan(6)
|
||||
test('opts.browser.write obj falls back to console where a method is not supplied', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var info = console.info
|
||||
console.info = function (o) {
|
||||
t.is(o.level, 30)
|
||||
t.is(o.msg, 'test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 30)
|
||||
is(o.msg, 'test')
|
||||
ok(o.time)
|
||||
console.info = info
|
||||
}
|
||||
var instance = require('../browser')({
|
||||
browser: {
|
||||
write: {
|
||||
error: function (o) {
|
||||
t.is(o.level, 50)
|
||||
t.is(o.test, 'test')
|
||||
t.ok(o.time)
|
||||
is(o.level, 50)
|
||||
is(o.test, 'test')
|
||||
ok(o.time)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
instance.error({test: 'test'})
|
||||
instance.info('test')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
function levelTest (name) {
|
||||
test(name + ' logs', function (t) {
|
||||
test(name + ' logs', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var msg = 'hello world'
|
||||
sink(name, function (args) {
|
||||
t.is(args[0], msg)
|
||||
t.end()
|
||||
is(args[0], msg)
|
||||
end()
|
||||
})
|
||||
pino({level: name})[name](msg)
|
||||
})
|
||||
|
||||
test('passing objects at level ' + name, function (t) {
|
||||
test('passing objects at level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var msg = { hello: 'world' }
|
||||
sink(name, function (args) {
|
||||
t.is(args[0], msg)
|
||||
t.end()
|
||||
is(args[0], msg)
|
||||
end()
|
||||
})
|
||||
pino({level: name})[name](msg)
|
||||
})
|
||||
|
||||
test('passing an object and a string at level ' + name, function (t) {
|
||||
test('passing an object and a string at level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var a = { hello: 'world' }
|
||||
var b = 'a string'
|
||||
sink(name, function (args) {
|
||||
t.is(args[0], a)
|
||||
t.is(args[1], b)
|
||||
t.end()
|
||||
is(args[0], a)
|
||||
is(args[1], b)
|
||||
end()
|
||||
})
|
||||
pino({level: name})[name](a, b)
|
||||
})
|
||||
|
||||
test('formatting logs as ' + name, function (t) {
|
||||
test('formatting logs as ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
sink(name, function (args) {
|
||||
t.is(args[0], 'hello %d')
|
||||
t.is(args[1], 42)
|
||||
t.end()
|
||||
is(args[0], 'hello %d')
|
||||
is(args[1], 42)
|
||||
end()
|
||||
})
|
||||
pino({level: name})[name]('hello %d', 42)
|
||||
})
|
||||
|
||||
test('passing error at level ' + name, function (t) {
|
||||
test('passing error at level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = new Error('myerror')
|
||||
sink(name, function (args) {
|
||||
t.is(args[0], err)
|
||||
t.end()
|
||||
is(args[0], err)
|
||||
end()
|
||||
})
|
||||
pino({level: name})[name](err)
|
||||
})
|
||||
|
||||
test('passing error with a serializer at level ' + name, function (t) {
|
||||
test('passing error with a serializer at level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
// in browser - should have no effect (should not crash)
|
||||
var err = new Error('myerror')
|
||||
sink(name, function (args) {
|
||||
t.is(args[0].err, err)
|
||||
t.end()
|
||||
is(args[0].err, err)
|
||||
end()
|
||||
})
|
||||
var instance = pino({
|
||||
level: name,
|
||||
@ -424,28 +428,28 @@ function levelTest (name) {
|
||||
instance[name]({err: err})
|
||||
})
|
||||
|
||||
test('child logger for level ' + name, function (t) {
|
||||
test('child logger for level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var msg = 'hello world'
|
||||
var parent = { hello: 'world' }
|
||||
sink(name, function (args) {
|
||||
t.is(args[0], parent)
|
||||
t.is(args[1], msg)
|
||||
t.end()
|
||||
is(args[0], parent)
|
||||
is(args[1], msg)
|
||||
end()
|
||||
})
|
||||
var instance = pino({level: name})
|
||||
var child = instance.child(parent)
|
||||
child[name](msg)
|
||||
})
|
||||
|
||||
test('child-child logger for level ' + name, function (t) {
|
||||
test('child-child logger for level ' + name, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var msg = 'hello world'
|
||||
var grandParent = { hello: 'world' }
|
||||
var parent = { hello: 'you' }
|
||||
sink(name, function (args) {
|
||||
t.is(args[0], grandParent)
|
||||
t.is(args[1], parent)
|
||||
t.is(args[2], msg)
|
||||
t.end()
|
||||
is(args[0], grandParent)
|
||||
is(args[1], parent)
|
||||
is(args[2], msg)
|
||||
end()
|
||||
})
|
||||
var instance = pino({level: name})
|
||||
var child = instance.child(grandParent).child(parent)
|
||||
@ -455,10 +459,10 @@ function levelTest (name) {
|
||||
|
||||
function consoleMethodTest (level, method) {
|
||||
if (!method) method = level
|
||||
test('pino().' + level + ' uses console.' + method, function (t) {
|
||||
test('pino().' + level + ' uses console.' + method, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
sink(method, function (args) {
|
||||
t.is(args[0], 'test')
|
||||
t.end()
|
||||
is(args[0], 'test')
|
||||
end()
|
||||
})
|
||||
var instance = require('../browser')({level: level})
|
||||
instance[level]('test')
|
||||
@ -466,12 +470,12 @@ function consoleMethodTest (level, method) {
|
||||
}
|
||||
|
||||
function absentConsoleMethodTest (method, fallback) {
|
||||
test('in absence of console.' + method + ', console.' + fallback + ' is used', function (t) {
|
||||
test('in absence of console.' + method + ', console.' + fallback + ' is used', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var fn = console[method]
|
||||
console[method] = undefined
|
||||
sink(fallback, function (args) {
|
||||
t.is(args[0], 'test')
|
||||
t.end()
|
||||
is(args[0], 'test')
|
||||
end()
|
||||
console[method] = fn
|
||||
})
|
||||
var instance = require('../browser')({level: method})
|
||||
|
||||
@ -13,24 +13,24 @@ function capture () {
|
||||
return ws
|
||||
}
|
||||
|
||||
test('pino uses LF by default', function (t) {
|
||||
t.plan(1)
|
||||
test('pino uses LF by default', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var stream = capture()
|
||||
var logger = pino(stream)
|
||||
logger.info('foo')
|
||||
logger.error('bar')
|
||||
t.ok(/foo[^\r\n]+\n[^\r\n]+bar[^\r\n]+\n/.test(stream.data))
|
||||
t.end()
|
||||
ok(/foo[^\r\n]+\n[^\r\n]+bar[^\r\n]+\n/.test(stream.data))
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('pino can log CRLF', function (t) {
|
||||
t.plan(1)
|
||||
test('pino can log CRLF', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var stream = capture()
|
||||
var logger = pino({
|
||||
crlf: true
|
||||
}, stream)
|
||||
logger.info('foo')
|
||||
logger.error('bar')
|
||||
t.ok(/foo[^\n]+\r\n[^\n]+bar[^\n]+\r\n/.test(stream.data))
|
||||
t.end()
|
||||
ok(/foo[^\n]+\r\n[^\n]+bar[^\n]+\r\n/.test(stream.data))
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
@ -9,13 +9,12 @@ var hostname = os.hostname()
|
||||
var level = 50
|
||||
var name = 'error'
|
||||
|
||||
test('err is serialized with additional properties set on the Error object', function (t) {
|
||||
t.plan(2)
|
||||
test('err is serialized with additional properties set on the Error object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Object.assign(new Error('myerror'), {foo: 'bar'})
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -30,15 +29,15 @@ test('err is serialized with additional properties set on the Error object', fun
|
||||
|
||||
instance.level = name
|
||||
instance[name](err)
|
||||
end()
|
||||
})
|
||||
|
||||
test('type should be retained, even if type is a property', function (t) {
|
||||
t.plan(2)
|
||||
test('type should be retained, even if type is a property', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Object.assign(new Error('myerror'), {type: 'bar'})
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -52,15 +51,15 @@ test('type should be retained, even if type is a property', function (t) {
|
||||
|
||||
instance.level = name
|
||||
instance[name](err)
|
||||
end()
|
||||
})
|
||||
|
||||
test('type, message and stack should be first level properties', function (t) {
|
||||
t.plan(2)
|
||||
test('type, message and stack should be first level properties', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Object.assign(new Error('foo'), { foo: 'bar' })
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -75,19 +74,19 @@ test('type, message and stack should be first level properties', function (t) {
|
||||
|
||||
instance.level = name
|
||||
instance[name](err)
|
||||
end()
|
||||
})
|
||||
|
||||
test('err serializer', function (t) {
|
||||
t.plan(2)
|
||||
test('err serializer', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Object.assign(new Error('myerror'), {foo: 'bar'})
|
||||
var instance = pino({
|
||||
serializers: {
|
||||
err: pino.stdSerializers.err
|
||||
}
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -104,15 +103,15 @@ test('err serializer', function (t) {
|
||||
|
||||
instance.level = name
|
||||
instance[name]({ err })
|
||||
end()
|
||||
})
|
||||
|
||||
test('an error with statusCode property is not confused for a http response', function (t) {
|
||||
t.plan(2)
|
||||
test('an error with statusCode property is not confused for a http response', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var err = Object.assign(new Error('StatusCodeErr'), { statusCode: 500 })
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
@ -127,4 +126,5 @@ test('an error with statusCode property is not confused for a http response', fu
|
||||
|
||||
instance.level = name
|
||||
instance[name](err)
|
||||
end()
|
||||
})
|
||||
|
||||
@ -9,14 +9,12 @@ var pid = process.pid
|
||||
var hostname = os.hostname()
|
||||
|
||||
function testEscape (ch, key) {
|
||||
test('correctly escape ' + ch, function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('correctly escape ' + ch, ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
name: 'hello'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 60,
|
||||
@ -24,7 +22,7 @@ function testEscape (ch, key) {
|
||||
msg: 'this contains ' + key,
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal('this contains ' + key)
|
||||
@ -77,13 +75,12 @@ toEscape.forEach(function (key) {
|
||||
testEscape(JSON.stringify(key), key)
|
||||
})
|
||||
|
||||
test('correctly escape `hello \\u001F world \\n \\u0022`', function (t) {
|
||||
t.plan(1)
|
||||
test('correctly escape `hello \\u001F world \\n \\u0022`', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
name: 'hello'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 60,
|
||||
@ -91,7 +88,7 @@ test('correctly escape `hello \\u001F world \\n \\u0022`', function (t) {
|
||||
msg: 'hello \u001F world \n \u0022',
|
||||
v: 1
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.fatal('hello \u001F world \n \u0022')
|
||||
|
||||
@ -7,23 +7,22 @@ var fork = require('child_process').fork
|
||||
var spawn = require('child_process').spawn
|
||||
var fixturesPath = path.join(__dirname, 'fixtures', 'events')
|
||||
|
||||
test('no event loop logs successfully', function (t) {
|
||||
t.plan(1)
|
||||
test('no event loop logs successfully', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var output = ''
|
||||
var child = fork(path.join(fixturesPath, 'no-event-loop.js'), {silent: true})
|
||||
|
||||
child.stdout.pipe(writeStream(function (s, enc, cb) {
|
||||
child.stdout.pipe(writeStream((s, enc, cb) => {
|
||||
output += s
|
||||
cb()
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.match(output, /"msg":"h"/)
|
||||
child.on('close', () => {
|
||||
is(/"msg":"h"/.test(output), true)
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('terminates when uncaughtException is fired with onTerminate registered', function (t) {
|
||||
t.plan(3)
|
||||
test('terminates when uncaughtException is fired with onTerminate registered', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var output = ''
|
||||
var errorOutput = ''
|
||||
var child = spawn(process.argv[0], [path.join(fixturesPath, 'uncaught-exception.js')], {silent: true})
|
||||
@ -39,14 +38,14 @@ test('terminates when uncaughtException is fired with onTerminate registered', f
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.match(output, /"msg":"h"/)
|
||||
t.match(output, /terminated/g)
|
||||
t.match(errorOutput, /this is not caught/g)
|
||||
is(/"msg":"h"/.test(output), true)
|
||||
is(/terminated/g.test(output), true)
|
||||
is(/this is not caught/g.test(errorOutput), true)
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('terminates when uncaughtException is fired without onTerminate registered', function (t) {
|
||||
t.plan(2)
|
||||
test('terminates when uncaughtException is fired without onTerminate registered', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var output = ''
|
||||
var child = spawn(process.argv[0], [path.join(fixturesPath, 'uncaught-exception-no-terminate.js')], {silent: true})
|
||||
|
||||
@ -55,17 +54,17 @@ test('terminates when uncaughtException is fired without onTerminate registered'
|
||||
cb()
|
||||
}))
|
||||
|
||||
child.on('exit', function (code) {
|
||||
t.is(code, 1)
|
||||
child.on('exit', (code) => {
|
||||
is(code, 1)
|
||||
})
|
||||
|
||||
child.on('close', function () {
|
||||
t.match(output, /"msg":"h"/)
|
||||
child.on('close', () => {
|
||||
is(/"msg":"h"/.test(output), true)
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('terminates on SIGHUP when no other handlers registered', function (t) {
|
||||
t.plan(2)
|
||||
test('terminates on SIGHUP when no other handlers registered', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var output = ''
|
||||
var child = spawn(process.argv[0], [path.join(fixturesPath, 'sighup-no-handler.js')], {silent: true})
|
||||
|
||||
@ -77,18 +76,18 @@ test('terminates on SIGHUP when no other handlers registered', function (t) {
|
||||
child.stderr.pipe(process.stdout)
|
||||
|
||||
child.on('exit', function (code) {
|
||||
t.is(code, 0)
|
||||
is(code, 0)
|
||||
})
|
||||
|
||||
child.on('close', function () {
|
||||
t.match(output, /"msg":"h"/)
|
||||
is(/"msg":"h"/.test(output), true)
|
||||
end()
|
||||
})
|
||||
|
||||
setTimeout(function () { child.kill('SIGHUP') }, 2000)
|
||||
})
|
||||
|
||||
test('lets app terminate when SIGHUP received with multiple handlers', function (t) {
|
||||
t.plan(3)
|
||||
test('lets app terminate when SIGHUP received with multiple handlers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var output = ''
|
||||
var child = spawn(process.argv[0], [path.join(fixturesPath, 'sighup-with-handler.js')], {silent: true})
|
||||
|
||||
@ -98,19 +97,19 @@ test('lets app terminate when SIGHUP received with multiple handlers', function
|
||||
}))
|
||||
|
||||
child.on('exit', function (code) {
|
||||
t.is(code, 0)
|
||||
is(code, 0)
|
||||
})
|
||||
|
||||
child.on('close', function () {
|
||||
t.match(output, /"msg":"h"/)
|
||||
t.match(output, /app sighup/)
|
||||
is(/"msg":"h"/.test(output), true)
|
||||
is(/app sighup/.test(output), true)
|
||||
end()
|
||||
})
|
||||
|
||||
setTimeout(function () { child.kill('SIGHUP') }, 2000)
|
||||
})
|
||||
|
||||
test('destination', function (t) {
|
||||
t.plan(2)
|
||||
test('destination', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var output = ''
|
||||
var child = spawn(process.argv[0], [path.join(fixturesPath, 'destination.js')], {silent: true})
|
||||
|
||||
@ -121,11 +120,12 @@ test('destination', function (t) {
|
||||
|
||||
child.stderr.pipe(process.stdout)
|
||||
|
||||
child.on('exit', function (code) {
|
||||
t.is(code, 0)
|
||||
child.on('exit', (code) => {
|
||||
is(code, 0)
|
||||
})
|
||||
|
||||
child.on('close', function () {
|
||||
t.notEqual(null, output.match(/"msg":"h"/))
|
||||
child.on('close', () => {
|
||||
is(/"msg":"h"/.test(output), true)
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
@ -7,7 +7,7 @@ var path = require('path')
|
||||
var writeStream = require('flush-write-stream')
|
||||
var fork = require('child_process').fork
|
||||
|
||||
test('extreme mode', function (t) {
|
||||
test('extreme mode', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, teardown}) => {
|
||||
var now = Date.now
|
||||
var hostname = os.hostname
|
||||
var proc = process
|
||||
@ -50,20 +50,20 @@ test('extreme mode', function (t) {
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.is(actual, expected)
|
||||
t.is(actual2.trim(), expected2)
|
||||
is(actual, expected)
|
||||
is(actual2.trim(), expected2)
|
||||
|
||||
t.teardown(function () {
|
||||
teardown(() => {
|
||||
os.hostname = hostname
|
||||
Date.now = now
|
||||
global.process = proc
|
||||
})
|
||||
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('extreme mode with child', function (t) {
|
||||
test('extreme mode with child', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, teardown}) => {
|
||||
var now = Date.now
|
||||
var hostname = os.hostname
|
||||
var proc = process
|
||||
@ -108,29 +108,31 @@ test('extreme mode with child', function (t) {
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.is(actual, expected)
|
||||
t.is(actual2.trim(), expected2)
|
||||
is(actual, expected)
|
||||
is(actual2.trim(), expected2)
|
||||
|
||||
t.teardown(function () {
|
||||
teardown(() => {
|
||||
os.hostname = hostname
|
||||
Date.now = now
|
||||
global.process = proc
|
||||
})
|
||||
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('throw an error if extreme is passed', function (t) {
|
||||
test('throw an error if extreme is passed', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var pino = require('..')
|
||||
t.throws(() => {
|
||||
throws(() => {
|
||||
pino({extreme: true})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('flush does nothing without extreme mode', function (t) {
|
||||
test('flush does nothing without extreme mode', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = require('..')()
|
||||
instance.flush()
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
@ -1,27 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
var writeStream = require('flush-write-stream')
|
||||
var split = require('split2')
|
||||
var os = require('os')
|
||||
var pid = process.pid
|
||||
var hostname = os.hostname()
|
||||
const writeStream = require('flush-write-stream')
|
||||
const split = require('split2')
|
||||
const os = require('os')
|
||||
const pid = process.pid
|
||||
const hostname = os.hostname()
|
||||
const v = 1
|
||||
|
||||
function sink (func) {
|
||||
var result = split(JSON.parse)
|
||||
function sink (func = () => {}) {
|
||||
const result = split(JSON.parse)
|
||||
result.pipe(writeStream.obj(func))
|
||||
return result
|
||||
}
|
||||
|
||||
function check (t, chunk, level, msg) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
function check (is, chunk, level, msg) {
|
||||
is(new Date(chunk.time) <= new Date(), true, 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: level,
|
||||
msg: msg,
|
||||
v: 1
|
||||
})
|
||||
is(chunk.pid, pid)
|
||||
is(chunk.hostname, hostname)
|
||||
is(chunk.level, level)
|
||||
is(chunk.msg, msg)
|
||||
is(chunk.v, v)
|
||||
}
|
||||
|
||||
module.exports.sink = sink
|
||||
|
||||
@ -9,14 +9,12 @@ var http = require('http')
|
||||
var pid = process.pid
|
||||
var hostname = os.hostname()
|
||||
|
||||
test('http request support', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('http request support', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError, teardown}) => {
|
||||
var originalReq
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -30,7 +28,7 @@ test('http request support', function (t) {
|
||||
remotePort: originalReq.connection.remotePort
|
||||
}
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
@ -38,27 +36,26 @@ test('http request support', function (t) {
|
||||
instance.info(req, 'my request')
|
||||
res.end('hello')
|
||||
}).listen(function (err) {
|
||||
t.error(err)
|
||||
t.teardown(server.close.bind(server))
|
||||
error(err)
|
||||
teardown(server.close.bind(server))
|
||||
|
||||
http.get('http://localhost:' + server.address().port, function (res) {
|
||||
res.resume()
|
||||
})
|
||||
})
|
||||
server.unref()
|
||||
})
|
||||
|
||||
test('http request support via serializer', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('http request support via serializer', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError, teardown}) => {
|
||||
var originalReq
|
||||
var instance = pino({
|
||||
serializers: {
|
||||
req: pino.stdSerializers.req
|
||||
}
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -72,7 +69,7 @@ test('http request support via serializer', function (t) {
|
||||
remotePort: originalReq.connection.remotePort
|
||||
}
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
@ -80,27 +77,26 @@ test('http request support via serializer', function (t) {
|
||||
instance.info({ req: req }, 'my request')
|
||||
res.end('hello')
|
||||
}).listen(function (err) {
|
||||
t.error(err)
|
||||
t.teardown(server.close.bind(server))
|
||||
error(err)
|
||||
teardown(server.close.bind(server))
|
||||
|
||||
http.get('http://localhost:' + server.address().port, function (res) {
|
||||
res.resume()
|
||||
})
|
||||
})
|
||||
server.unref()
|
||||
})
|
||||
|
||||
test('http request support via serializer without request connection', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('http request support via serializer without request connection', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError, teardown}) => {
|
||||
var originalReq
|
||||
var instance = pino({
|
||||
serializers: {
|
||||
req: pino.stdSerializers.req
|
||||
}
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -112,7 +108,7 @@ test('http request support via serializer without request connection', function
|
||||
headers: originalReq.headers
|
||||
}
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
@ -121,23 +117,22 @@ test('http request support via serializer without request connection', function
|
||||
instance.info({ req: req }, 'my request')
|
||||
res.end('hello')
|
||||
}).listen(function (err) {
|
||||
t.error(err)
|
||||
t.teardown(server.close.bind(server))
|
||||
error(err)
|
||||
teardown(server.close.bind(server))
|
||||
|
||||
http.get('http://localhost:' + server.address().port, function (res) {
|
||||
res.resume()
|
||||
})
|
||||
})
|
||||
server.unref()
|
||||
})
|
||||
|
||||
test('http response support', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('http response support', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError, teardown}) => {
|
||||
var originalRes
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -148,7 +143,7 @@ test('http response support', function (t) {
|
||||
header: originalRes._header
|
||||
}
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
@ -156,27 +151,26 @@ test('http response support', function (t) {
|
||||
res.end('hello')
|
||||
instance.info(res, 'my response')
|
||||
}).listen(function (err) {
|
||||
t.error(err)
|
||||
t.teardown(server.close.bind(server))
|
||||
error(err)
|
||||
teardown(server.close.bind(server))
|
||||
|
||||
http.get('http://localhost:' + server.address().port, function (res) {
|
||||
res.resume()
|
||||
})
|
||||
})
|
||||
server.unref()
|
||||
})
|
||||
|
||||
test('http response support via a serializer', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('http response support via a serializer', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError, teardown}) => {
|
||||
var originalRes
|
||||
var instance = pino({
|
||||
serializers: {
|
||||
res: pino.stdSerializers.res
|
||||
}
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -187,7 +181,7 @@ test('http response support via a serializer', function (t) {
|
||||
header: originalRes._header
|
||||
}
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
@ -195,27 +189,26 @@ test('http response support via a serializer', function (t) {
|
||||
res.end('hello')
|
||||
instance.info({ res: res }, 'my response')
|
||||
}).listen(function (err) {
|
||||
t.error(err)
|
||||
t.teardown(server.close.bind(server))
|
||||
error(err)
|
||||
teardown(server.close.bind(server))
|
||||
|
||||
http.get('http://localhost:' + server.address().port, function (res) {
|
||||
res.resume()
|
||||
})
|
||||
})
|
||||
server.unref()
|
||||
})
|
||||
|
||||
test('http request support via serializer in a child', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('http request support via serializer in a child', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError, teardown}) => {
|
||||
var originalReq
|
||||
var instance = pino({
|
||||
serializers: {
|
||||
req: pino.stdSerializers.req
|
||||
}
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -229,7 +222,7 @@ test('http request support via serializer in a child', function (t) {
|
||||
remotePort: originalReq.connection.remotePort
|
||||
}
|
||||
})
|
||||
cb()
|
||||
end()
|
||||
}))
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
@ -238,11 +231,12 @@ test('http request support via serializer in a child', function (t) {
|
||||
child.info('my request')
|
||||
res.end('hello')
|
||||
}).listen(function (err) {
|
||||
t.error(err)
|
||||
t.teardown(server.close.bind(server))
|
||||
error(err)
|
||||
teardown(server.close.bind(server))
|
||||
|
||||
http.get('http://localhost:' + server.address().port, function (res) {
|
||||
res.resume()
|
||||
})
|
||||
})
|
||||
server.unref()
|
||||
})
|
||||
|
||||
@ -3,51 +3,45 @@
|
||||
var test = require('tap').test
|
||||
var pino = require('../')
|
||||
|
||||
test('can check if current level enabled', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('can check if current level enabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'debug'})
|
||||
t.is(true, log.isLevelEnabled('debug'))
|
||||
is(true, log.isLevelEnabled('debug'))
|
||||
end()
|
||||
})
|
||||
|
||||
test('can check if level enabled after level set', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('can check if level enabled after level set', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino()
|
||||
t.is(false, log.isLevelEnabled('debug'))
|
||||
is(false, log.isLevelEnabled('debug'))
|
||||
log.level = 'debug'
|
||||
t.is(true, log.isLevelEnabled('debug'))
|
||||
is(true, log.isLevelEnabled('debug'))
|
||||
end()
|
||||
})
|
||||
|
||||
test('can check if higher level enabled', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('can check if higher level enabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'debug'})
|
||||
t.is(true, log.isLevelEnabled('error'))
|
||||
is(true, log.isLevelEnabled('error'))
|
||||
end()
|
||||
})
|
||||
|
||||
test('can check if lower level is disabled', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('can check if lower level is disabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'error'})
|
||||
t.is(false, log.isLevelEnabled('trace'))
|
||||
is(false, log.isLevelEnabled('trace'))
|
||||
end()
|
||||
})
|
||||
|
||||
test('can check if child has current level enabled', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('can check if child has current level enabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino().child({level: 'debug'})
|
||||
t.is(true, log.isLevelEnabled('debug'))
|
||||
t.is(true, log.isLevelEnabled('error'))
|
||||
t.is(false, log.isLevelEnabled('trace'))
|
||||
is(true, log.isLevelEnabled('debug'))
|
||||
is(true, log.isLevelEnabled('error'))
|
||||
is(false, log.isLevelEnabled('trace'))
|
||||
end()
|
||||
})
|
||||
|
||||
test('can check if custom level is enabled', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
test('can check if custom level is enabled', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var log = pino({level: 'debug'})
|
||||
log.addLevel('foo', 35)
|
||||
t.is(true, log.isLevelEnabled('foo'))
|
||||
t.is(true, log.isLevelEnabled('error'))
|
||||
t.is(false, log.isLevelEnabled('trace'))
|
||||
is(true, log.isLevelEnabled('foo'))
|
||||
is(true, log.isLevelEnabled('error'))
|
||||
is(false, log.isLevelEnabled('trace'))
|
||||
end()
|
||||
})
|
||||
|
||||
@ -5,8 +5,7 @@ var pino = require('../')
|
||||
var sink = require('./helper').sink
|
||||
var check = require('./helper').check
|
||||
|
||||
test('set the level by string', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level by string', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [{
|
||||
level: 50,
|
||||
msg: 'this is an error'
|
||||
@ -16,7 +15,7 @@ test('set the level by string', function (t) {
|
||||
}]
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
var current = expected.shift()
|
||||
check(t, chunk, current.level, current.msg)
|
||||
check(is, chunk, current.level, current.msg)
|
||||
cb()
|
||||
}))
|
||||
|
||||
@ -24,18 +23,18 @@ test('set the level by string', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
end()
|
||||
})
|
||||
|
||||
test('the wrong level throws', function (t) {
|
||||
t.plan(1)
|
||||
test('the wrong level throws', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino()
|
||||
t.throws(function () {
|
||||
throws(function () {
|
||||
instance.level = 'kaboom'
|
||||
})
|
||||
end()
|
||||
})
|
||||
|
||||
test('set the level by number', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level by number', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [{
|
||||
level: 50,
|
||||
msg: 'this is an error'
|
||||
@ -45,7 +44,7 @@ test('set the level by number', function (t) {
|
||||
}]
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
var current = expected.shift()
|
||||
check(t, chunk, current.level, current.msg)
|
||||
check(is, chunk, current.level, current.msg)
|
||||
cb()
|
||||
}))
|
||||
|
||||
@ -53,10 +52,10 @@ test('set the level by number', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
end()
|
||||
})
|
||||
|
||||
test('set the level by number via string method', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level by number via string method', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [{
|
||||
level: 50,
|
||||
msg: 'this is an error'
|
||||
@ -66,7 +65,7 @@ test('set the level by number via string method', function (t) {
|
||||
}]
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
var current = expected.shift()
|
||||
check(t, chunk, current.level, current.msg)
|
||||
check(is, chunk, current.level, current.msg)
|
||||
cb()
|
||||
}))
|
||||
|
||||
@ -74,33 +73,33 @@ test('set the level by number via string method', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes level string mappings', function (t) {
|
||||
t.plan(1)
|
||||
t.equal(pino.levels.values.error, 50)
|
||||
test('exposes level string mappings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
is(pino.levels.values.error, 50)
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposes level number mappings', function (t) {
|
||||
t.plan(1)
|
||||
t.equal(pino.levels.labels[50], 'error')
|
||||
test('exposes level number mappings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
is(pino.levels.labels[50], 'error')
|
||||
end()
|
||||
})
|
||||
|
||||
test('returns level integer', function (t) {
|
||||
t.plan(1)
|
||||
test('returns level integer', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({ level: 'error' })
|
||||
t.equal(instance.levelVal, 50)
|
||||
is(instance.levelVal, 50)
|
||||
end()
|
||||
})
|
||||
|
||||
test('child returns level integer', function (t) {
|
||||
t.plan(1)
|
||||
test('child returns level integer', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({ level: 'error' })
|
||||
var child = parent.child({ foo: 'bar' })
|
||||
t.equal(child.levelVal, 50)
|
||||
is(child.levelVal, 50)
|
||||
end()
|
||||
})
|
||||
|
||||
test('set the level via constructor', function (t) {
|
||||
t.plan(4)
|
||||
test('set the level via constructor', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [{
|
||||
level: 50,
|
||||
msg: 'this is an error'
|
||||
@ -110,22 +109,23 @@ test('set the level via constructor', function (t) {
|
||||
}]
|
||||
var instance = pino({ level: 'error' }, sink(function (chunk, enc, cb) {
|
||||
var current = expected.shift()
|
||||
check(t, chunk, current.level, current.msg)
|
||||
check(is, chunk, current.level, current.msg)
|
||||
cb()
|
||||
}))
|
||||
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
end()
|
||||
})
|
||||
|
||||
test('level-change event', function (t) {
|
||||
test('level-change event', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino()
|
||||
var handle = function (lvl, val, prevLvl, prevVal) {
|
||||
t.is(lvl, 'trace')
|
||||
t.is(val, 10)
|
||||
t.is(prevLvl, 'info')
|
||||
t.is(prevVal, 30)
|
||||
is(lvl, 'trace')
|
||||
is(val, 10)
|
||||
is(prevLvl, 'info')
|
||||
is(prevVal, 30)
|
||||
}
|
||||
instance.on('level-change', handle)
|
||||
instance.level = 'trace'
|
||||
@ -149,69 +149,72 @@ test('level-change event', function (t) {
|
||||
instance.removeListener('level-change', l2)
|
||||
instance.level = 'info'
|
||||
|
||||
t.is(count, 6)
|
||||
t.end()
|
||||
is(count, 6)
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('enable', function (t) {
|
||||
test('enable', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
level: 'trace',
|
||||
enabled: false
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.fail('no data should be logged')
|
||||
fail('no data should be logged')
|
||||
}))
|
||||
|
||||
Object.keys(pino.levels.values).forEach(function (level) {
|
||||
instance[level]('hello world')
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('silent level', function (t) {
|
||||
test('silent level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
level: 'silent'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.fail('no data should be logged')
|
||||
fail('no data should be logged')
|
||||
}))
|
||||
|
||||
Object.keys(pino.levels.values).forEach(function (level) {
|
||||
instance[level]('hello world')
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('silent is a noop', function (t) {
|
||||
test('silent is a noop', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({
|
||||
level: 'silent'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.fail('no data should be logged')
|
||||
fail('no data should be logged')
|
||||
}))
|
||||
|
||||
instance['silent']('hello world')
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('silent stays a noop after level changes', function (t) {
|
||||
test('silent stays a noop after level changes', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var noop = require('../lib/tools').noop
|
||||
var instance = pino({
|
||||
level: 'silent'
|
||||
}, sink(function (chunk, enc, cb) {
|
||||
t.fail('no data should be logged')
|
||||
fail('no data should be logged')
|
||||
}))
|
||||
|
||||
instance.level = 'trace'
|
||||
t.notEqual(instance[instance.level], noop)
|
||||
isNot(instance[instance.level], noop)
|
||||
|
||||
instance.level = 'silent'
|
||||
instance['silent']('hello world')
|
||||
t.is(instance[instance.level], noop)
|
||||
is(instance[instance.level], noop)
|
||||
|
||||
t.end()
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposed levels', function (t) {
|
||||
t.plan(1)
|
||||
t.deepEqual(Object.keys(pino.levels.values), [
|
||||
test('exposed levels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
same(Object.keys(pino.levels.values), [
|
||||
'fatal',
|
||||
'error',
|
||||
'warn',
|
||||
@ -219,11 +222,11 @@ test('exposed levels', function (t) {
|
||||
'debug',
|
||||
'trace'
|
||||
])
|
||||
end()
|
||||
})
|
||||
|
||||
test('exposed labels', function (t) {
|
||||
t.plan(1)
|
||||
t.deepEqual(Object.keys(pino.levels.labels), [
|
||||
test('exposed labels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
same(Object.keys(pino.levels.labels), [
|
||||
'10',
|
||||
'20',
|
||||
'30',
|
||||
@ -231,10 +234,10 @@ test('exposed labels', function (t) {
|
||||
'50',
|
||||
'60'
|
||||
])
|
||||
end()
|
||||
})
|
||||
|
||||
test('setting level in child', function (t) {
|
||||
t.plan(4)
|
||||
test('setting level in child', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var expected = [{
|
||||
level: 50,
|
||||
msg: 'this is an error'
|
||||
@ -244,7 +247,7 @@ test('setting level in child', function (t) {
|
||||
}]
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
var current = expected.shift()
|
||||
check(t, chunk, current.level, current.msg)
|
||||
check(is, chunk, current.level, current.msg)
|
||||
cb()
|
||||
})).child({ level: 30 })
|
||||
|
||||
@ -252,4 +255,5 @@ test('setting level in child', function (t) {
|
||||
instance.info('hello world')
|
||||
instance.error('this is an error')
|
||||
instance.fatal('this is fatal')
|
||||
end()
|
||||
})
|
||||
|
||||
@ -8,12 +8,11 @@ var sink = require('./helper').sink
|
||||
var pid = process.pid
|
||||
var hostname = os.hostname()
|
||||
|
||||
test('metadata works', function (t) {
|
||||
t.plan(7)
|
||||
test('metadata works', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var dest = sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -26,24 +25,24 @@ test('metadata works', function (t) {
|
||||
var instance = pino({}, {
|
||||
[Symbol.for('needsMetadata')]: true,
|
||||
write: function (chunk) {
|
||||
t.equal(instance, this.lastLogger)
|
||||
t.equal(30, this.lastLevel)
|
||||
t.equal('a msg', this.lastMsg)
|
||||
t.ok(Number(this.lastTime) >= now)
|
||||
t.deepEqual({ hello: 'world' }, this.lastObj)
|
||||
is(instance, this.lastLogger)
|
||||
is(30, this.lastLevel)
|
||||
is('a msg', this.lastMsg)
|
||||
ok(Number(this.lastTime) >= now)
|
||||
same({ hello: 'world' }, this.lastObj)
|
||||
dest.write(chunk)
|
||||
}
|
||||
})
|
||||
|
||||
instance.info({ hello: 'world' }, 'a msg')
|
||||
end()
|
||||
})
|
||||
|
||||
test('child loggers works', function (t) {
|
||||
t.plan(6)
|
||||
test('child loggers works', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var dest = sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -56,24 +55,24 @@ test('child loggers works', function (t) {
|
||||
var instance = pino({}, {
|
||||
[Symbol.for('needsMetadata')]: true,
|
||||
write: function (chunk) {
|
||||
t.equal(child, this.lastLogger)
|
||||
t.equal(30, this.lastLevel)
|
||||
t.equal('a msg', this.lastMsg)
|
||||
t.deepEqual({ from: 'child' }, this.lastObj)
|
||||
is(child, this.lastLogger)
|
||||
is(30, this.lastLevel)
|
||||
is('a msg', this.lastMsg)
|
||||
same({ from: 'child' }, this.lastObj)
|
||||
dest.write(chunk)
|
||||
}
|
||||
})
|
||||
|
||||
var child = instance.child({ hello: 'world' })
|
||||
child.info({ from: 'child' }, 'a msg')
|
||||
end()
|
||||
})
|
||||
|
||||
test('without object', function (t) {
|
||||
t.plan(6)
|
||||
test('without object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var dest = sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -84,23 +83,23 @@ test('without object', function (t) {
|
||||
var instance = pino({}, {
|
||||
[Symbol.for('needsMetadata')]: true,
|
||||
write: function (chunk) {
|
||||
t.equal(instance, this.lastLogger)
|
||||
t.equal(30, this.lastLevel)
|
||||
t.equal('a msg', this.lastMsg)
|
||||
t.equal(null, this.lastObj)
|
||||
is(instance, this.lastLogger)
|
||||
is(30, this.lastLevel)
|
||||
is('a msg', this.lastMsg)
|
||||
is(null, this.lastObj)
|
||||
dest.write(chunk)
|
||||
}
|
||||
})
|
||||
|
||||
instance.info('a msg')
|
||||
end()
|
||||
})
|
||||
|
||||
test('without msg', function (t) {
|
||||
t.plan(6)
|
||||
test('without msg', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var dest = sink(function (chunk, enc, cb) {
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
t.deepEqual(chunk, {
|
||||
same(chunk, {
|
||||
pid: pid,
|
||||
hostname: hostname,
|
||||
level: 30,
|
||||
@ -111,13 +110,14 @@ test('without msg', function (t) {
|
||||
var instance = pino({}, {
|
||||
[Symbol.for('needsMetadata')]: true,
|
||||
write: function (chunk) {
|
||||
t.equal(instance, this.lastLogger)
|
||||
t.equal(30, this.lastLevel)
|
||||
t.equal(undefined, this.lastMsg)
|
||||
t.deepEqual({ hello: 'world' }, this.lastObj)
|
||||
is(instance, this.lastLogger)
|
||||
is(30, this.lastLevel)
|
||||
is(undefined, this.lastMsg)
|
||||
same({ hello: 'world' }, this.lastObj)
|
||||
dest.write(chunk)
|
||||
}
|
||||
})
|
||||
|
||||
instance.info({ hello: 'world' })
|
||||
end()
|
||||
})
|
||||
|
||||
@ -7,8 +7,7 @@ var path = require('path')
|
||||
var writeStream = require('flush-write-stream')
|
||||
var fork = require('child_process').fork
|
||||
|
||||
test('can be enabled via constructor', function (t) {
|
||||
t.plan(1)
|
||||
test('can be enabled via constructor', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var actual = ''
|
||||
var child = fork(path.join(__dirname, 'fixtures', 'pretty', 'basic.js'), {silent: true})
|
||||
|
||||
@ -18,12 +17,12 @@ test('can be enabled via constructor', function (t) {
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.notEqual(actual.match(/\(123456 on abcdefghijklmnopqr\): h/), null)
|
||||
isNot(actual.match(/\(123456 on abcdefghijklmnopqr\): h/), null)
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('can be enabled via constructor with pretty configuration', function (t) {
|
||||
t.plan(1)
|
||||
test('can be enabled via constructor with pretty configuration', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var actual = ''
|
||||
var child = fork(path.join(__dirname, 'fixtures', 'pretty', 'level-first.js'), {silent: true})
|
||||
|
||||
@ -33,12 +32,12 @@ test('can be enabled via constructor with pretty configuration', function (t) {
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.notEqual(actual.match(/^INFO.*h/), null)
|
||||
isNot(actual.match(/^INFO.*h/), null)
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('can be enabled via constructor with prettifier', function (t) {
|
||||
t.plan(1)
|
||||
test('can be enabled via constructor with prettifier', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var actual = ''
|
||||
var child = fork(path.join(__dirname, 'fixtures', 'pretty', 'pretty-factory.js'), {silent: true})
|
||||
|
||||
@ -48,23 +47,23 @@ test('can be enabled via constructor with prettifier', function (t) {
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.notEqual(actual.match(/^INFO.*h/), null)
|
||||
isNot(actual.match(/^INFO.*h/), null)
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
test('does not throw error when enabled with stream specified', function (t) {
|
||||
test('does not throw error when enabled with stream specified', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
pino({prettyPrint: true}, process.stdout)
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('can send pretty print to custom stream', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('can send pretty print to custom stream', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var dest = new Writable({
|
||||
objectMode: true,
|
||||
write (formatted, enc, cb) {
|
||||
t.match(formatted, /^INFO.*foo\n$/)
|
||||
cb()
|
||||
is(/^INFO.*foo\n$/.test(formatted), true)
|
||||
end()
|
||||
}
|
||||
})
|
||||
|
||||
@ -77,17 +76,16 @@ test('can send pretty print to custom stream', function (t) {
|
||||
log.info('foo')
|
||||
})
|
||||
|
||||
test('ignores `undefined` from prettifier', function (t) {
|
||||
t.plan(1)
|
||||
test('ignores `undefined` from prettifier', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var actual = ''
|
||||
var child = fork(path.join(__dirname, 'fixtures', 'pretty', 'skipped-output.js'), {silent: true})
|
||||
|
||||
child.stdout.pipe(writeStream(function (s, enc, cb) {
|
||||
actual += s
|
||||
cb()
|
||||
}))
|
||||
|
||||
child.on('close', function () {
|
||||
t.is(actual, '')
|
||||
is(actual, '')
|
||||
end()
|
||||
})
|
||||
})
|
||||
|
||||
@ -4,69 +4,76 @@ var test = require('tap').test
|
||||
var pino = require('../')
|
||||
var sink = require('./helper').sink
|
||||
|
||||
test('redact option – throws if not array', function (t) {
|
||||
t.throws(() => {
|
||||
test('redact option – throws if not array', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(() => {
|
||||
pino({redact: 'req.headers.cookie'})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('redact option – throws if array does not only contain strings', function (t) {
|
||||
t.throws(() => {
|
||||
test('redact option – throws if array does not only contain strings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(() => {
|
||||
pino({redact: ['req.headers.cookie', {}]})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('redact option – throws if array contains an invalid path', function (t) {
|
||||
t.throws(() => {
|
||||
test('redact option – throws if array contains an invalid path', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(() => {
|
||||
pino({redact: ['req,headers.cookie']})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('redact.paths option – throws if not array', function (t) {
|
||||
t.throws(() => {
|
||||
test('redact.paths option – throws if not array', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(() => {
|
||||
pino({redact: {paths: 'req.headers.cookie'}})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('redact.paths option – throws if array does not only contain strings', function (t) {
|
||||
t.throws(() => {
|
||||
test('redact.paths option – throws if array does not only contain strings', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(() => {
|
||||
pino({redact: {paths: ['req.headers.cookie', {}]}})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('redact.paths option – throws if array contains an invalid path', function (t) {
|
||||
t.throws(() => {
|
||||
test('redact.paths option – throws if array contains an invalid path', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(() => {
|
||||
pino({redact: {paths: ['req,headers.cookie']}})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('redact.censor option – throws if censor is a function', function (t) {
|
||||
t.throws(() => {
|
||||
test('redact.censor option – throws if censor is a function', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
throws(() => {
|
||||
pino({redact: {paths: ['req.headers.cookie'], censor: () => {}}})
|
||||
})
|
||||
t.end()
|
||||
|
||||
end()
|
||||
})
|
||||
|
||||
test('redact option – top level key', function (t) {
|
||||
test('redact option – top level key', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: ['key']}, sink(function (o, enc, cb) {
|
||||
t.equals(o.key, '[Redacted]')
|
||||
t.end()
|
||||
is(o.key, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
key: {redact: 'me'}
|
||||
})
|
||||
})
|
||||
|
||||
test('redact option – object', function (t) {
|
||||
test('redact option – object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: ['req.headers.cookie']}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
req: {
|
||||
@ -84,10 +91,10 @@ test('redact option – object', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('redact option – child object', function (t) {
|
||||
test('redact option – child object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: ['req.headers.cookie']}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.child({
|
||||
@ -106,10 +113,10 @@ test('redact option – child object', function (t) {
|
||||
}).info('message completed')
|
||||
})
|
||||
|
||||
test('redact option – interpolated object', function (t) {
|
||||
test('redact option – interpolated object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: ['req.headers.cookie']}, sink(function (o, enc, cb) {
|
||||
t.equals(JSON.parse(o.msg.replace(/test /, '')).req.headers.cookie, '[Redacted]')
|
||||
t.end()
|
||||
is(JSON.parse(o.msg.replace(/test /, '')).req.headers.cookie, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info('test', {
|
||||
@ -128,10 +135,10 @@ test('redact option – interpolated object', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.paths option – object', function (t) {
|
||||
test('redact.paths option – object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie']}}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
req: {
|
||||
@ -149,10 +156,10 @@ test('redact.paths option – object', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.paths option – child object', function (t) {
|
||||
test('redact.paths option – child object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie']}}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.child({
|
||||
@ -171,10 +178,10 @@ test('redact.paths option – child object', function (t) {
|
||||
}).info('message completed')
|
||||
})
|
||||
|
||||
test('redact.paths option – interpolated object', function (t) {
|
||||
test('redact.paths option – interpolated object', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie']}}, sink(function (o, enc, cb) {
|
||||
t.equals(JSON.parse(o.msg.replace(/test /, '')).req.headers.cookie, '[Redacted]')
|
||||
t.end()
|
||||
is(JSON.parse(o.msg.replace(/test /, '')).req.headers.cookie, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
|
||||
instance.info('test', {
|
||||
@ -193,10 +200,10 @@ test('redact.paths option – interpolated object', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.censor option – sets the redact value', function (t) {
|
||||
test('redact.censor option – sets the redact value', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie'], censor: 'test'}}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, 'test')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, 'test')
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
req: {
|
||||
@ -214,10 +221,10 @@ test('redact.censor option – sets the redact value', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.remove option – removes both key and value', function (t) {
|
||||
test('redact.remove option – removes both key and value', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie'], remove: true}}, sink(function (o, enc, cb) {
|
||||
t.equals('cookie' in o.req.headers, false)
|
||||
t.end()
|
||||
is('cookie' in o.req.headers, false)
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
req: {
|
||||
@ -235,21 +242,21 @@ test('redact.remove option – removes both key and value', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.remove – top level key', function (t) {
|
||||
test('redact.remove – top level key', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['key'], remove: true}}, sink(function (o, enc, cb) {
|
||||
t.equals('key' in o, false)
|
||||
t.end()
|
||||
is('key' in o, false)
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
key: {redact: 'me'}
|
||||
})
|
||||
})
|
||||
|
||||
test('redact.paths preserves original object values after the log write', function (t) {
|
||||
test('redact.paths preserves original object values after the log write', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: ['req.headers.cookie']}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.equals(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
is(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
end()
|
||||
}))
|
||||
const obj = {
|
||||
req: {
|
||||
@ -268,11 +275,11 @@ test('redact.paths preserves original object values after the log write', functi
|
||||
instance.info(obj)
|
||||
})
|
||||
|
||||
test('redact.paths preserves original object values after the log write', function (t) {
|
||||
test('redact.paths preserves original object values after the log write', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie']}}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.equals(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
is(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
end()
|
||||
}))
|
||||
const obj = {
|
||||
req: {
|
||||
@ -291,11 +298,11 @@ test('redact.paths preserves original object values after the log write', functi
|
||||
instance.info(obj)
|
||||
})
|
||||
|
||||
test('redact.censor preserves original object values after the log write', function (t) {
|
||||
test('redact.censor preserves original object values after the log write', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie'], censor: 'test'}}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, 'test')
|
||||
t.equals(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, 'test')
|
||||
is(obj.req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
|
||||
end()
|
||||
}))
|
||||
const obj = {
|
||||
req: {
|
||||
@ -314,11 +321,11 @@ test('redact.censor preserves original object values after the log write', funct
|
||||
instance.info(obj)
|
||||
})
|
||||
|
||||
test('redact.remove preserves original object values after the log write', function (t) {
|
||||
test('redact.remove preserves original object values after the log write', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: {paths: ['req.headers.cookie'], remove: true}}, sink(function (o, enc, cb) {
|
||||
t.equals('cookie' in o.req.headers, false)
|
||||
t.equals('cookie' in obj.req.headers, true)
|
||||
t.end()
|
||||
is('cookie' in o.req.headers, false)
|
||||
is('cookie' in obj.req.headers, true)
|
||||
end()
|
||||
}))
|
||||
const obj = {
|
||||
req: {
|
||||
@ -337,12 +344,12 @@ test('redact.remove preserves original object values after the log write', funct
|
||||
instance.info(obj)
|
||||
})
|
||||
|
||||
test('redact – supports last position wildcard paths', function (t) {
|
||||
test('redact – supports last position wildcard paths', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: ['req.headers.*']}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.equals(o.req.headers.host, '[Redacted]')
|
||||
t.equals(o.req.headers.connection, '[Redacted]')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
is(o.req.headers.host, '[Redacted]')
|
||||
is(o.req.headers.connection, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
req: {
|
||||
@ -360,10 +367,10 @@ test('redact – supports last position wildcard paths', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('redact – supports intermediate wildcard paths', function (t) {
|
||||
test('redact – supports intermediate wildcard paths', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({redact: ['req.*.cookie']}, sink(function (o, enc, cb) {
|
||||
t.equals(o.req.headers.cookie, '[Redacted]')
|
||||
t.end()
|
||||
is(o.req.headers.cookie, '[Redacted]')
|
||||
end()
|
||||
}))
|
||||
instance.info({
|
||||
req: {
|
||||
|
||||
@ -11,26 +11,25 @@ var childSerializers = {
|
||||
test: function () { return 'child' }
|
||||
}
|
||||
|
||||
test('serializers override values', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('serializers override values', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({ serializers: parentSerializers }, sink(function (o, enc, cb) {
|
||||
t.is(o.test, 'parent')
|
||||
cb()
|
||||
is(o.test, 'parent')
|
||||
end()
|
||||
}))
|
||||
parent.child({ serializers: childSerializers })
|
||||
|
||||
parent.fatal({test: 'test'})
|
||||
})
|
||||
|
||||
test('child does not overwrite parent serializers', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
test('child does not overwrite parent serializers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var c = 0
|
||||
var parent = pino({ serializers: parentSerializers }, sink(function (o, enc, cb) {
|
||||
c++
|
||||
if (c === 1) t.is(o.test, 'parent')
|
||||
if (c === 2) t.is(o.test, 'child')
|
||||
if (c === 1) is(o.test, 'parent')
|
||||
if (c === 2) {
|
||||
is(o.test, 'child')
|
||||
end()
|
||||
}
|
||||
cb()
|
||||
}))
|
||||
var child = parent.child({ serializers: childSerializers })
|
||||
@ -39,25 +38,22 @@ test('child does not overwrite parent serializers', function (t) {
|
||||
child.fatal({test: 'test'})
|
||||
})
|
||||
|
||||
test('children inherit parent serializers', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('children inherit parent serializers', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({ serializers: parentSerializers }, sink(function (o, enc, cb) {
|
||||
t.is(o.test, 'parent')
|
||||
is(o.test, 'parent')
|
||||
end()
|
||||
}))
|
||||
|
||||
var child = parent.child({a: 'property'})
|
||||
child.fatal({test: 'test'})
|
||||
})
|
||||
|
||||
test('children serializers get called', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('children serializers get called', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({
|
||||
test: 'this'
|
||||
}, sink(function (o, enc, cb) {
|
||||
t.is(o.test, 'child')
|
||||
cb()
|
||||
is(o.test, 'child')
|
||||
end()
|
||||
}))
|
||||
|
||||
var child = parent.child({ 'a': 'property', serializers: childSerializers })
|
||||
@ -65,15 +61,13 @@ test('children serializers get called', function (t) {
|
||||
child.fatal({test: 'test'})
|
||||
})
|
||||
|
||||
test('children serializers get called when inherited from parent', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
test('children serializers get called when inherited from parent', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var parent = pino({
|
||||
test: 'this',
|
||||
serializers: parentSerializers
|
||||
}, sink(function (o, enc, cb) {
|
||||
t.is(o.test, 'pass')
|
||||
cb()
|
||||
is(o.test, 'pass')
|
||||
end()
|
||||
}))
|
||||
|
||||
var child = parent.child({serializers: {test: function () { return 'pass' }}})
|
||||
@ -81,8 +75,7 @@ test('children serializers get called when inherited from parent', function (t)
|
||||
child.fatal({test: 'fail'})
|
||||
})
|
||||
|
||||
test('non overriden serializers are available in the children', function (t) {
|
||||
t.plan(4)
|
||||
test('non-overridden serializers are available in the children', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var pSerializers = {
|
||||
onlyParent: function () { return 'parent' },
|
||||
shared: function () { return 'parent' }
|
||||
@ -97,10 +90,13 @@ test('non overriden serializers are available in the children', function (t) {
|
||||
|
||||
var parent = pino({ serializers: pSerializers }, sink(function (o, enc, cb) {
|
||||
c++
|
||||
if (c === 1) t.is(o.shared, 'child')
|
||||
if (c === 2) t.is(o.onlyParent, 'parent')
|
||||
if (c === 3) t.is(o.onlyChild, 'child')
|
||||
if (c === 4) t.is(o.onlyChild, 'test')
|
||||
if (c === 1) is(o.shared, 'child')
|
||||
if (c === 2) is(o.onlyParent, 'parent')
|
||||
if (c === 3) is(o.onlyChild, 'child')
|
||||
if (c === 4) {
|
||||
is(o.onlyChild, 'test')
|
||||
end()
|
||||
}
|
||||
cb()
|
||||
}))
|
||||
|
||||
@ -112,8 +108,7 @@ test('non overriden serializers are available in the children', function (t) {
|
||||
parent.fatal({onlyChild: 'test'})
|
||||
})
|
||||
|
||||
test('Symbol.for(\'pino.*\') serializer', function (t) {
|
||||
t.plan(6)
|
||||
test('Symbol.for(\'pino.*\') serializer', ({plan, end, ok, same, notSame, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var globalSerializer = {
|
||||
[Symbol.for('pino.*')]: function (obj) {
|
||||
if (obj.lionel === 'richie') {
|
||||
@ -125,9 +120,27 @@ test('Symbol.for(\'pino.*\') serializer', function (t) {
|
||||
var c = 0
|
||||
var logger = pino({serializers: globalSerializer}, sink(function (o, enc, cb) {
|
||||
c++
|
||||
if (c === 1) { t.match(o, {lionel: 'richie'}); t.notMatch(o, ['hello', 'it', 'you', 'looking']) }
|
||||
if (c === 2) { t.match(o, {hello: 'is', it: 'me', you: 'are', looking: 'for'}); t.notMatch(o, ['lionel']) }
|
||||
if (c === 3) { t.match(o, {lionel: 'richie'}); t.notMatch(o, ['pid', 'hostname']) }
|
||||
if (c === 1) {
|
||||
is(o.lionel, 'richie')
|
||||
isNot(o.hello, 'is')
|
||||
isNot(o.it, 'me')
|
||||
isNot(o.you, 'are')
|
||||
isNot(o.looking, 'for')
|
||||
}
|
||||
if (c === 2) {
|
||||
is(o.lionel, 'richie')
|
||||
is(o.hello, 'is')
|
||||
is(o.it, 'me')
|
||||
is(o.you, 'are')
|
||||
is(o.looking, 'for')
|
||||
}
|
||||
if (c === 3) {
|
||||
is(o.lionel, 'richie')
|
||||
is('pid' in o, false)
|
||||
is('hostname' in o, false)
|
||||
notSame(o, ['pid', 'hostname'])
|
||||
end()
|
||||
}
|
||||
cb()
|
||||
}))
|
||||
|
||||
|
||||
@ -4,67 +4,67 @@ var test = require('tap').test
|
||||
var pino = require('../')
|
||||
var sink = require('./helper').sink
|
||||
|
||||
test('pino exposes standard time functions', function (t) {
|
||||
t.plan(4)
|
||||
t.ok(pino.stdTimeFunctions)
|
||||
t.ok(pino.stdTimeFunctions.epochTime)
|
||||
t.ok(pino.stdTimeFunctions.unixTime)
|
||||
t.ok(pino.stdTimeFunctions.nullTime)
|
||||
test('pino exposes standard time functions', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
ok(pino.stdTimeFunctions)
|
||||
ok(pino.stdTimeFunctions.epochTime)
|
||||
ok(pino.stdTimeFunctions.unixTime)
|
||||
ok(pino.stdTimeFunctions.nullTime)
|
||||
end()
|
||||
})
|
||||
|
||||
test('pino accepts external time functions', function (t) {
|
||||
t.plan(2)
|
||||
test('pino accepts external time functions', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var opts = {
|
||||
timestamp: function () {
|
||||
return ',"time":"none"'
|
||||
}
|
||||
}
|
||||
var instance = pino(opts, sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.hasOwnProperty('time'), true)
|
||||
t.equal(chunk.time, 'none')
|
||||
is(chunk.hasOwnProperty('time'), true)
|
||||
is(chunk.time, 'none')
|
||||
end()
|
||||
}))
|
||||
instance.info('foobar')
|
||||
})
|
||||
|
||||
test('inserts timestamp by default', function (t) {
|
||||
test('inserts timestamp by default', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.hasOwnProperty('time'), true)
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than timestamp')
|
||||
t.equal(chunk.msg, 'foobar')
|
||||
is(chunk.hasOwnProperty('time'), true)
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than timestamp')
|
||||
is(chunk.msg, 'foobar')
|
||||
cb()
|
||||
t.end()
|
||||
end()
|
||||
}))
|
||||
instance.info('foobar')
|
||||
})
|
||||
|
||||
test('omits timestamp with option', function (t) {
|
||||
test('omits timestamp with option', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var instance = pino({timestamp: false}, sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.hasOwnProperty('time'), false)
|
||||
t.equal(chunk.msg, 'foobar')
|
||||
is(chunk.hasOwnProperty('time'), false)
|
||||
is(chunk.msg, 'foobar')
|
||||
cb()
|
||||
t.end()
|
||||
end()
|
||||
}))
|
||||
instance.info('foobar')
|
||||
})
|
||||
|
||||
test('child inserts timestamp by default', function (t) {
|
||||
test('child inserts timestamp by default', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino(sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.hasOwnProperty('time'), true)
|
||||
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than timestamp')
|
||||
t.equal(chunk.msg, 'foobar')
|
||||
is(chunk.hasOwnProperty('time'), true)
|
||||
ok(new Date(chunk.time) <= new Date(), 'time is greater than timestamp')
|
||||
is(chunk.msg, 'foobar')
|
||||
cb()
|
||||
t.end()
|
||||
end()
|
||||
}))
|
||||
var instance = logger.child({component: 'child'})
|
||||
instance.info('foobar')
|
||||
})
|
||||
|
||||
test('child omits timestamp with option', function (t) {
|
||||
test('child omits timestamp with option', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
|
||||
var logger = pino({timestamp: false}, sink(function (chunk, enc, cb) {
|
||||
t.equal(chunk.hasOwnProperty('time'), false)
|
||||
t.equal(chunk.msg, 'foobar')
|
||||
is(chunk.hasOwnProperty('time'), false)
|
||||
is(chunk.msg, 'foobar')
|
||||
cb()
|
||||
t.end()
|
||||
end()
|
||||
}))
|
||||
var instance = logger.child({component: 'child'})
|
||||
instance.info('foobar')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user