diff --git a/lib/winston/container.js b/lib/winston/container.js index 1c6f1140c..57720306a 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -40,7 +40,11 @@ module.exports = class Container { // 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.transports = Array.isArray(existing) ? existing.slice() : [existing]; + } else { + options.transports = []; + } 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); + }); + }); });