webpack-log icon indicating copy to clipboard operation
webpack-log copied to clipboard

Write to STDERR, not STDOUT (for webpack --json > stats.json)

Open ypresto opened this issue 7 years ago • 9 comments

  • 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

ypresto avatar Nov 30 '18 03:11 ypresto

STDERR foe errors, why we should write information in error buffer? Please provide reproducible test repo where JSON is broken

alexander-akait avatar Nov 30 '18 09:11 alexander-akait

Created test repo: https://github.com/ypresto/webpack-log-stdout-json-issue

ypresto avatar Nov 30 '18 14:11 ypresto

See also: https://github.com/webpack/webpack/issues/1904 and https://github.com/johnagan/clean-webpack-plugin/issues/11

chrisblossom avatar Mar 13 '19 18:03 chrisblossom

Solutions:

  1. Write always in STDERR (but other tools/plugins write in STDOUT)
  2. Allow to defined env variable to change behaviour
  3. Check if user want to write in stdout write logs in STDERR

alexander-akait avatar Mar 14 '19 09:03 alexander-akait

Any feedback

alexander-akait avatar Mar 14 '19 09:03 alexander-akait

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 avatar Mar 17 '19 06:03 ypresto

@ypresto hm, can we find something same inside webpack?

alexander-akait avatar Mar 18 '19 09:03 alexander-akait

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 avatar Mar 22 '19 19:03 chrisblossom

@chrisblossom we can look logic for ProgressPlugin and determinate where he writes output and use this logic too

alexander-akait avatar Mar 23 '19 13:03 alexander-akait