Write to STDERR, not STDOUT (for webpack --json > stats.json)
- Operating System: macOS 10.13.6
- Node Version: v8.7.0
- NPM Version: 5.4.2
- webpack Version: 4.12.0
- webpack-dev-server Version: N/A
- [ ] This is a bug
- [x] This is a feature request
- [x] This is a modification request
Code
$ node -e '"log,debug,info,warn,error".split(",").forEach(level => require("webpack-log")({ name: "test" })[level](level))' > /dev/null
⚠ 「test」: warn
✖ 「test」: error
Expected Behavior
Always write to STDERR, or at least configurable from caller.
Actual Behavior
Only warn and error are written to STDERR, others are written to STDOUT.
For Features; What is the motivation and/or use-case for the feature?
webpack --json > stats.json will cause corrupted JSON if log written to STDOUT.
https://github.com/s-panferov/awesome-typescript-loader/issues/461
STDERR foe errors, why we should write information in error buffer? Please provide reproducible test repo where JSON is broken
Created test repo: https://github.com/ypresto/webpack-log-stdout-json-issue
See also: https://github.com/webpack/webpack/issues/1904 and https://github.com/johnagan/clean-webpack-plugin/issues/11
Solutions:
- Write always in
STDERR(but other tools/plugins write in STDOUT) - Allow to defined env variable to change behaviour
- Check if user want to write in
stdoutwrite logs inSTDERR
Any feedback
https://github.com/webpack/webpack/issues/1904#issuecomment-172762537
loaders and plugins should not log to the console. Loaders can log errors and warnings with this.emitWarning and this.emitError. Plugins can add them to compilation.warnings and compilation.errors.
According to this, the messages written to webpack-log is kind message (like progress, debug info, etc) for user and is not formal output of webpack plugins or loaders. So IMO they should always be written to STDERR.
@ypresto hm, can we find something same inside webpack?
Write always in STDERR (but other tools/plugins write in STDOUT)
I think this is the proper way to log outside of webpack, which this plugin aims to do. Otherwise I think you should use webpack's this.emitWarning, this.emitError, compilation.warnings or compilation.errors.
hm, can we find something same inside webpack?
@evilebottnawi Could you be more specific what you are asking?
@chrisblossom we can look logic for ProgressPlugin and determinate where he writes output and use this logic too