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

console transport: send all levels to stdout not stderr by default #1332

Merged
merged 4 commits into from
Jun 1, 2018

Conversation

DABH
Copy link
Contributor

@DABH DABH commented May 25, 2018

This addresses the common points brought up in #927 and #1024 . This change makes 'debug' level output go to stdout not stderr by default for the console transport. The behavior is still controllable by specifying the debugStdout option for the transport or by passing a levels array, just as before. Tests updated to reflect new default and line added to upgrade guide to mention this since it's a breaking change.

@DABH DABH requested a review from indexzero May 25, 2018 07:39
Copy link
Member

@indexzero indexzero left a comment

Choose a reason for hiding this comment

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

@DABH code you wrote is 👍, but I think there may have been some confusion around the nature of the change itself.

The goal I meant to outline in my comment was to have all logging content be sent to stdout, not just the debug level.

I've made comments on what needs to change based on that expectation. If you can give this another pass then we'll be good to go here ^_^

* @returns {mixed} - TODO: add return description.
* @param {mixed} levels - An Array of string names of levels whose output
* should go to stderr
* @param {mixed} debugStdout - Whether the 'debug' level should be sent to
Copy link
Member

Choose a reason for hiding this comment

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

Just remove this option since debugStdout is now the default behavior.

* should go to stderr
* @param {mixed} debugStdout - Whether the 'debug' level should be sent to
* stdout (default true as of `winston@3`).
* @returns {mixed} - An Object containing the levels to send to stderr.
* @private
*/
_getStderrLevels(levels, debugStdout) {
Copy link
Member

Choose a reason for hiding this comment

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

This whole function can be removed since by default all levels should now go to stdout unless the user explicitly provides logging levels they would like to go to stderr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. The constructor now takes stderrLevels as an optional string array as one of the potential options. Defaults to {}.

@@ -56,7 +56,7 @@ function assertStderrLevels(transport, stderrLevels) {

describe('Console transport', function () {
describe('with defaults', function () {
it('logs all levels (EXCEPT error and debug) to stdout', function () {
it('logs all levels (EXCEPT error) to stdout', function () {
Copy link
Member

Choose a reason for hiding this comment

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

It's just all levels now:

it('logs all levels to stdout', function () {

});

it("should set stderrLevels to ['error', 'debug'] by default", assertStderrLevels(
it("should set stderrLevels to ['error'] by default", assertStderrLevels(
Copy link
Member

Choose a reason for hiding this comment

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

it('should set stderrLevels to [] by default', assertStderrLevels(

transports.defaults,
['error', 'debug']
['error']
Copy link
Member

Choose a reason for hiding this comment

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

This would just be an empty array now.

[]

@@ -74,14 +74,14 @@ describe('Console transport', function () {
stdMocks.restore();
var output = stdMocks.flush();
assume(output.stderr).is.an('array');
assume(output.stderr).length(2);
assume(output.stderr).length(1);
Copy link
Member

Choose a reason for hiding this comment

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

assume(output.stderr).length(0);

assume(output.stdout).is.an('array');
assume(output.stdout).length(5);
assume(output.stdout).length(6);
Copy link
Member

Choose a reason for hiding this comment

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

assume(output.stdout).length(7);

UPGRADE-3.0.md Outdated
@@ -26,6 +26,7 @@
### Transports
- `winston.transports.Memory` was removed. Use any Node.js `stream.Writeable` with a large `highWaterMark` instance instead.
- When writing transports use `winston-transport` instead of `winston.Transport`
- In `winston.transports.Console`, log level 'debug' ouptut is now sent to stdout by default rather than stderr (controlled by `debugStdout` option)
Copy link
Member

Choose a reason for hiding this comment

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

  • In winston.transports.Console output for all log levels is now sent to stdout by default.
    • debugStdout option has been removed.
    • stderrLevels now defaults to []

@indexzero indexzero mentioned this pull request May 31, 2018
@DABH
Copy link
Contributor Author

DABH commented May 31, 2018

Thanks for the review @indexzero ! I believe these address all your comments but just let me know. Thanks!

@DABH DABH changed the title console transport: send 'debug' level output to stdout not stderr by default console transport: send all levels to stdout not stderr by default May 31, 2018
@indexzero indexzero merged commit 189559b into winstonjs:master Jun 1, 2018
Mizumaki pushed a commit to Mizumaki/winston that referenced this pull request Jun 11, 2020
…instonjs#1332)

* console transport: send 'debug' level output to stdout not stderr by default

* fix style

* Address PR comments / everything goes to stdout by default

* update doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants