From a470ab55f21056d8803fa9dc849cfe1665f2be3a Mon Sep 17 00:00:00 2001 From: indexzero Date: Wed, 28 Oct 2015 23:58:23 -0700 Subject: [PATCH] [refactor] Simply the initialization logic for exception handling. [breaking] No longer respect the `handleExceptions` option to `new winston.Logger`. Instead just pass in the `exceptionHandlers` option itself. --- lib/winston/logger.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index ea259a634..f29e05ac4 100755 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -72,15 +72,7 @@ var Logger = exports.Logger = function (options) { } if (options.exceptionHandlers) { - handleExceptions = true; - options.exceptionHandlers.forEach(function (handler) { - self._hnames.push(handler.name); - self.exceptionHandlers[handler.name] = handler; - }); - } - - if (options.handleExceptions || handleExceptions) { - this.handleExceptions(); + this.handleExceptions(options.exceptionHandlers); } }; @@ -377,8 +369,9 @@ Logger.prototype.close = function () { }; // -// ### function handleExceptions () -// Handles `uncaughtException` events for the current process +// ### function handleExceptions ([tr0, tr1...] || tr0, tr1, ...) +// Handles `uncaughtException` events for the current process by +// ADDING any handlers passed in. // Logger.prototype.handleExceptions = function () { var args = Array.prototype.slice.call(arguments), @@ -394,6 +387,7 @@ Logger.prototype.handleExceptions = function () { } }); + this.exceptionHandlers = this.exceptionHandlers || {}; handlers.forEach(function (handler) { self.exceptionHandlers[handler.name] = handler; });