Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

refactor: upgrades "winston" package to v3 #1293

Closed
wants to merge 1 commit into from
Closed

refactor: upgrades "winston" package to v3 #1293

wants to merge 1 commit into from

Conversation

kettanaito
Copy link
Contributor

@kettanaito kettanaito commented Mar 28, 2019

🚀 Why this change?

Upgrades winston package to version 3. Follows the migration guides to adjust existing usage for breaking API changes of the winston package.

  • Uses winston.createLogger instead of winston.Logger
  • Removes deprecated colors field from the logger config
  • Uses format field with format.colorize() for logs' colors (retains the previously set colors mapping)

📝 Related issues and Pull Requests

✅ What didn't I forget?

  • To write docs
  • To write tests
  • To put Conventional Changelog prefixes in front of all my commits and run npm run lint

@kettanaito
Copy link
Contributor Author

Hi, @honzajavorek. Could you please assist me in verifying these changes retain the previous behavior of both internal and external (repoter) loggers?

I've used CLIReporter-test to verify the changes on local. The test successfully passes after my changes. However, I would like to confirm on your side that the upgrade of the package went successfully on the usage level.

loggerStub.transports.console.silent = true;
reporterOutputLoggerStub.transports.console.silent = true;
[loggerStub, reporterOutputLoggerStub].forEach((logger) => {
logger.configure({ silent: true });
Copy link
Contributor Author

@kettanaito kettanaito Mar 28, 2019

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.

Copy link
Contributor

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() and sinon.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).

@honzajavorek
Copy link
Contributor

Thanks! I'll take a look tomorrow 👍

Copy link
Contributor

@honzajavorek honzajavorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made two comments. Let me know if that answers your questions, I'm happy to help.

On a related note, with @dariagrudzien we recently worked on upgrading Winston in one private library we have in @apiaryio and it seems the v3 doesn't emit the logging event anymore when the logger logs something. It is a shame, as that was one of the nicer ways how to inspect the logger in tests without any sinon-ing around. I'm afraid it is used in Dredd's tests as well, so watch out for that during the upgrade.

loggerStub.transports.console.silent = true;
reporterOutputLoggerStub.transports.console.silent = true;
[loggerStub, reporterOutputLoggerStub].forEach((logger) => {
logger.configure({ silent: true });
Copy link
Contributor

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() and sinon.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).

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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a good idea to mutate logger instances

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 npm test output cluttered (like in this case).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@kettanaito
Copy link
Contributor Author

Thanks for the support, Honzo. I don't have the connection at the moment, so we can continue on this upgrade once I'm in the office. Hope that's fine.

@kettanaito
Copy link
Contributor Author

Closed in favor of #1303.

@kettanaito kettanaito closed this Apr 2, 2019
@kettanaito kettanaito deleted the 1225-winston-upgrade branch April 2, 2019 11:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade winston to 3.x
2 participants