From e0e06d3af560b5903344d9c3ebab22a44d07c3c8 Mon Sep 17 00:00:00 2001 From: Marc Udoff Date: Mon, 30 Nov 2015 20:25:42 -0500 Subject: [PATCH] Any stream with an on function will register for error --- lib/bunyan.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/bunyan.js b/lib/bunyan.js index 0640d6d..6adacde 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -547,9 +547,6 @@ Logger.prototype.addStream = function addStream(s, defaultLevel) { if (!s.stream) { s.stream = fs.createWriteStream(s.path, {flags: 'a', encoding: 'utf8'}); - s.stream.on('error', function (err) { - self.emit('error', err, s); - }); if (!s.closeOnExit) { s.closeOnExit = true; } @@ -579,6 +576,11 @@ Logger.prototype.addStream = function addStream(s, defaultLevel) { throw new TypeError('unknown stream type "' + s.type + '"'); } + if(typeof s.stream.on === 'function') { + s.stream.on('error', function (err) { + self.emit('error', err, s); + }); + } self.streams.push(s); delete self.haveNonRawStreams; // reset }