-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add stderrLevels option to Console Transport and update docs. #630
Conversation
Nice improvement! I also have been wanting to control level-to-output stream mapping for a while. |
Let's use that improvement the world needs it 👍 |
This seems to be a valuable improvement. |
this.showLevel = options.showLevel === undefined ? true : options.showLevel; | ||
this.label = options.label || null; | ||
this.logstash = options.logstash || false; | ||
this.stderrLevels = (function (levels, debugStdout) { |
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.
An immediately invoked function expression is a rather cumbersome way to do this. Could you clean it up a bit?
I am +1 on this if we can cleanup the obtuse syntax a bit. There has to be a simpler way to setup the initial state. |
@indexzero Thanks for the code review, I made some changes following your advice. How does this look? Should I move the |
- Let users choose which levels to log to stderr instead of stdout - Maintain backwards compatibility with previous options/behavior
This is good. Especially the deprecation notice. This will land in |
This was cherry-picked. |
This PR lets users choose which levels to log to stderr instead of stdout. It's non-breaking and fully backwards compatible with previous options and behavior. I hope you like it 👍
The new Console Transport option is
stderrLevels
, which accepts an Array of strings containing the levels to log to stderr instead of stdout.The code is thoroughly unit tested, contains input validation, and converts the Array provided to
options.stderrLevels
to an Object for faster key-lookup times. TheREADME.md
anddocs/transports.md
files have also been updated to better reflect the current state of the Console Transport.Example usage:
Create a Console that logs 'error' and 'warn' levels to stderr, and other levels to stdout:
var console = new (winston.transports.Console)({ stderrLevels: ['error', 'warn'] });
Create a Console that logs nothing to stderr and everything to stdout:
var console = new (winston.transports.Console)({ stderrLevels: [] });
Create a Console that logs certain custom levels to stderr:
Backwards Compatibility
The current state of the Console has it logging these levels to stderr:
error
anddebug
(ifoptions.debugStdout
is false)error
(ifoptions.debugStdout
is true)This behavior is kept as the default for
stderrLevels
in order to ensure this change is non-breaking:stderrLevels
defaults to the equivalent of(options.debugStdout ? ['error'] : ['error', 'debug'])
. This means that everyone not using the newstderrLevels
option will see no change in the Console Transport's behavior.Note: Another PR from July 2013 exists for the same feature (#286), but caused breaking changes and was never merged. Hopefully since this new PR is non-breaking and takes the
debugStdout
option into consideration, uses an Object for fast key-lookup times, includes unit tests, input validation and updated documentation, the feature we both want to see can finally get in in 2015 :)