Skip to content

Commit

Permalink
Support writing the logs to stderr
Browse files Browse the repository at this point in the history
Fixes #85.
  • Loading branch information
mcollina committed Sep 11, 2016
1 parent c100719 commit 01937e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Object.defineProperty(nums, '100', {
})

function pino (opts, stream) {
if (opts && opts._writableState) {
if (opts && (opts.writable || opts._writableState)) {
stream = opts
opts = null
}
Expand Down
24 changes: 24 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,27 @@ test('correctly escape msg strings', function (t) {

instance.fatal('this contains "')
})

test('correctly support node v4+ stderr', function (t) {
t.plan(1)

// stderr inherits from Stream, rather than Writable
var dest = {
writable: true,
write: function (chunk) {
chunk = JSON.parse(chunk)
delete chunk.time
t.deepEqual(chunk, {
pid: pid,
hostname: hostname,
level: 60,
msg: 'a message',
v: 1
})
}
}

var instance = pino(dest)

instance.fatal('a message')
})

0 comments on commit 01937e4

Please sign in to comment.