Skip to content

Commit

Permalink
fix: properly allow passing non-arry transport (#2256)
Browse files Browse the repository at this point in the history
* fix: properly allow passing non-arry transport

* re-add Remark comment

* fix property name
  • Loading branch information
Tanuel committed Jan 2, 2023
1 parent 95af182 commit eec59af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/winston/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
20 changes: 20 additions & 0 deletions test/unit/winston/container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit eec59af

Please sign in to comment.