-
Notifications
You must be signed in to change notification settings - Fork 280
refactor: upgrades "winston" package to v3 #1293
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
const winston = require('winston'); | ||
const { createLogger, transports, format } = require('winston'); | ||
|
||
module.exports = new (winston.Logger)({ | ||
module.exports = new createLogger({ | ||
transports: [ | ||
new (winston.transports.Console)({ colorize: true }), | ||
new transports.Console({ colorize: true }), | ||
], | ||
levels: { | ||
debug: 2, | ||
warn: 1, | ||
error: 0, | ||
}, | ||
colors: { | ||
debug: 'cyan', | ||
warn: 'yellow', | ||
error: 'red', | ||
}, | ||
format: format.colorize({ | ||
colors: { | ||
debug: 'cyan', | ||
warn: 'yellow', | ||
error: 'red', | ||
}, | ||
}), | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,17 @@ describe('CLIReporter', () => { | |
let test = {}; | ||
|
||
before(() => { | ||
loggerStub.transports.console.silent = true; | ||
reporterOutputLoggerStub.transports.console.silent = true; | ||
[loggerStub, reporterOutputLoggerStub].forEach((logger) => { | ||
logger.configure({ silent: true }); | ||
}) | ||
}); | ||
|
||
after(() => { | ||
loggerStub.transports.console.silent = false; | ||
reporterOutputLoggerStub.transports.console.silent = false; | ||
// Is this really a good idea to mutate logger instances | ||
// vs creating logger instances for tests using the same factory function? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Nope π But as per my previous comment, currently the logging isn't done in a way it would be easy to test. It is planned, but if you want to keep this PR scoped to Winston upgrade, you should restrain yourself from trying to solve this problem as well. We can (should!) do it as one of the next steps. We can limit the mutations though by ommitting silencing of the logging in tests, which is not for the purpose of the test itself, but only for the purpose of not having the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarifying. I will remove this mutation and see the test output. Let's keep this pull request scoped to prevent the complexity of the changes. We can refactor the usage of logging later, I'd be glad to. |
||
[loggerStub, reporterOutputLoggerStub].forEach((logger) => { | ||
logger.configure({ silent: false }); | ||
}) | ||
}); | ||
|
||
describe('when starting', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm particularly insterested in how to verify this silent toggling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short: I think it is in the test only to prevent the logger to print to the terminal during the tests. I wouldn't be bothered about it in this phase. If the
--loglevel=silent
option works correctly for Dredd (important), feel free to omit the silencing and leave the logging chatty in tests (nice to have).Long: What I'm trying to achieve is to use winston for Dredd's "application logging" (roughly equal to stderr), and to replace winston completely for the reporters and any other "application output" (roughly equal to stdout). Also, I'd like the logger or the "output rendering component" (not in place yet) to be testable in better ways than it is now. Currently, magic with
proxyquire()
andsinon.stub()
-s is necessary every time the tests want to verify what was displayed to the user.The refactoring is hairy and complex, and especially gradually updating the tests to be able to test the same stuff even after changes to the logging infrastructure is tedious. For that reason, I consider having the logger silent during the tests as something nice to have at this moment, and I omitted it many times in my previous PRs. The result is that the output of
npm test
is a bit messy now, but I count with the fact this gets figured out once we have a better way to test the logger (like dependency injection).