From 1c05014782e7e27af09142b601d7248ebd9ef7f0 Mon Sep 17 00:00:00 2001 From: wbt Date: Wed, 24 Feb 2021 08:20:16 -0500 Subject: [PATCH 1/2] Cleanup exception/rejection handler B4 replacing. Attempts to address comment: https://github.com/winstonjs/winston/pull/1824#issuecomment-784935345 --- lib/winston/logger.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index dc7866854..7523c69d7 100644 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -107,6 +107,12 @@ class Logger extends Transform { // Hoist other options onto this instance. this.levels = levels || this.levels || config.npm.levels; this.level = level; + if(this.exceptions !== undefined) { + this.exceptions.unhandle(); + } + if(this.rejections !== undefined) { + this.rejections.unhandle(); + } this.exceptions = new ExceptionHandler(this); this.rejections = new RejectionHandler(this); this.profilers = {}; From b7e8f771324898406278d5327e452301dbf03b13 Mon Sep 17 00:00:00 2001 From: wbt Date: Wed, 24 Feb 2021 08:26:56 -0500 Subject: [PATCH 2/2] Fix undefined check to use typeof avoiding possible variable shadowing isssue --- lib/winston/logger.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index 7523c69d7..0f5f53e15 100644 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -107,10 +107,10 @@ class Logger extends Transform { // Hoist other options onto this instance. this.levels = levels || this.levels || config.npm.levels; this.level = level; - if(this.exceptions !== undefined) { + if(typeof this.exceptions !== "undefined") { this.exceptions.unhandle(); } - if(this.rejections !== undefined) { + if(typeof this.rejections !== "undefined") { this.rejections.unhandle(); } this.exceptions = new ExceptionHandler(this);