From 632379030ead3606280612299c617225bef5bea0 Mon Sep 17 00:00:00 2001 From: Evan Oxfeld Date: Mon, 4 Jun 2012 23:23:12 -0400 Subject: [PATCH] Re-emit fs.createWriteStream errors --- README.md | 1 + lib/bunyan.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 24a32d2..5bc0011 100644 --- a/README.md +++ b/README.md @@ -443,6 +443,7 @@ Supported stream types are: "level": "warn" } +- Bunyan re-emits error events if the file cannot be opened successfully. # License diff --git a/lib/bunyan.js b/lib/bunyan.js index 5d0abf7..6b02041 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -25,6 +25,7 @@ var os = require('os'); var fs = require('fs'); var util = require('util'); var assert = require('assert'); +var EventEmitter = require('events').EventEmitter; @@ -169,6 +170,8 @@ function resolveLevel(nameOrNum) { //---- Logger class +Logger.prototype = new EventEmitter; + /** * Create a Logger instance. * @@ -316,7 +319,9 @@ function Logger(options, _childOptions, _childSimple) { case 'file': if (!s.stream) { s.stream = fs.createWriteStream(s.path, - {flags: 'a', encoding: 'utf8'}); + {flags: 'a', encoding: 'utf8'}).on('error', function(err) { + self.emit('error', err); + }); if (!s.closeOnExit) { s.closeOnExit = true; }