From 17573d6fdad26e61a79e70cab4ccfa219d5589b5 Mon Sep 17 00:00:00 2001 From: Tanuel Date: Wed, 14 Dec 2022 13:29:13 +0100 Subject: [PATCH 1/3] fix: properly allow passing non-arry transport --- lib/winston/container.js | 8 +++++--- test/unit/winston/container.test.js | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/winston/container.js b/lib/winston/container.js index 1c6f1140c..b9d2ca87c 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -38,9 +38,11 @@ module.exports = class Container { options = Object.assign({}, options || this.options); const existing = options.transports || this.options.transports; - // Remark: Make sure if we have an array of transports we slice it to - // make copies of those references. - options.transports = existing ? existing.slice() : []; + if(existing) { + options.transport = Array.isArray(existing) ? existing.slice() : [existing]; + } else { + options.transport = []; + } const logger = createLogger(options); logger.on('close', () => this._delete(id)); diff --git a/test/unit/winston/container.test.js b/test/unit/winston/container.test.js index ab587d7e2..3008ee08b 100644 --- a/test/unit/winston/container.test.js +++ b/test/unit/winston/container.test.js @@ -66,4 +66,24 @@ describe('Container', function () { assume(all.someOtherLogger._readableState.pipes).equals(all.someLogger._readableState.pipes); }); }); + + describe('explicit non-array transport', function () { + var transport = new winston.transports.Http({ port: 9412 }); + var container = new winston.Container({ transports: transport }); + var all = {}; + + it('.get(some-logger)', function () { + all.someLogger = container.get('some-logger'); + assume(all.someLogger._readableState.pipes).instanceOf(winston.transports.Http); + assume(all.someLogger._readableState.pipes).equals(transport); + }); + + it('.get(some-other-logger)', function () { + all.someOtherLogger = container.get('some-other-logger'); + + assume(all.someOtherLogger._readableState.pipes).instanceOf(winston.transports.Http); + assume(all.someOtherLogger._readableState.pipes).equals(transport); + assume(all.someOtherLogger._readableState.pipes).equals(all.someLogger._readableState.pipes); + }); + }); }); From af6bb6ca8644d9b7a4c0deaa8685b2b292f6b02f Mon Sep 17 00:00:00 2001 From: Tanuel Date: Wed, 14 Dec 2022 13:34:49 +0100 Subject: [PATCH 2/3] re-add Remark comment --- lib/winston/container.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/winston/container.js b/lib/winston/container.js index b9d2ca87c..457e89f28 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -38,6 +38,8 @@ module.exports = class Container { options = Object.assign({}, options || this.options); const existing = options.transports || this.options.transports; + // Remark: Make sure if we have an array of transports we slice it to + // make copies of those references. if(existing) { options.transport = Array.isArray(existing) ? existing.slice() : [existing]; } else { From e8241f8454946886dc70b0f72170261f252ddd3c Mon Sep 17 00:00:00 2001 From: Tanuel Date: Mon, 2 Jan 2023 10:26:10 +0100 Subject: [PATCH 3/3] fix property name --- lib/winston/container.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/winston/container.js b/lib/winston/container.js index 457e89f28..57720306a 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -40,10 +40,10 @@ module.exports = class Container { // Remark: Make sure if we have an array of transports we slice it to // make copies of those references. - if(existing) { - options.transport = Array.isArray(existing) ? existing.slice() : [existing]; + if (existing) { + options.transports = Array.isArray(existing) ? existing.slice() : [existing]; } else { - options.transport = []; + options.transports = []; } const logger = createLogger(options);