Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly allow passing non-arry transport #2256

Merged
merged 3 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.transport = Array.isArray(existing) ? existing.slice() : [existing];
Tanuel marked this conversation as resolved.
Show resolved Hide resolved
} else {
options.transport = [];
}

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);
});
});
});