Skip to content

Commit

Permalink
Merge pull request #17 from mcollina/throw-missing-bindings
Browse files Browse the repository at this point in the history
Throw if creating a child logger without bindings.
  • Loading branch information
David Mark Clements committed Mar 31, 2016
2 parents 5236950 + 7b7173d commit 8603c35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function setup (result, funcs, level, stream, opts, serializers, stringify) {
result.child = child

function child (bindings) {
if (!opts) {
if (!bindings) {
throw new Error('missing bindings for child logger')
}

Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,17 @@ test('http request support via serializer in a child', function (t) {
})
})
})

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()
})
})

0 comments on commit 8603c35

Please sign in to comment.