From 01937e4e9b27cbe6d5537a6dcfd3521866eff155 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sun, 11 Sep 2016 08:59:09 +0200 Subject: [PATCH] Support writing the logs to stderr Fixes #85. --- pino.js | 2 +- test/basic.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pino.js b/pino.js index e8feaca03..c2efc47ea 100644 --- a/pino.js +++ b/pino.js @@ -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 } diff --git a/test/basic.test.js b/test/basic.test.js index 8ef24c592..b6b75a21e 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -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') +})