use the webpack infrastructure logger (if available) rather than outputting to the console directly so that webpack --silent mode is respected.
Goal
Webpack supports a --silent option and our webpack plugins should respect that
In webpack 4 it is common to output stats as json and pipe it to a file (e.g. webpack --mode=production --profile --json > stats/stats.json). This requires silent mode to be respected. Note: webpack 5 stats don't need piping as they are generated withnpx webpack --profile --json=compilation-stats.json. See https://webpack.js.org/api/stats/
The logger returned with getLogger doesn't output anything to the console in the event of an error, so getInfrastructureLogger is used, as the output is more useful.
BugsnagBuildReporterPlugin will not use the webpack logger when a custom logger option is supplied.
webpack <= 4.37 doesn't have the logging API so:
BugsnagBuildReporterPlugin falls back to its built in logger (unless a custom option logger is supplied); and
BugsnagSourceMapUploaderPlugin falls back to console (there is no custom logger option).
Changeset
BugsnagBuildReporterPlugin: use the webpack "infrastructure" logger for logging, if present
BugsnagSourceMapUploaderPlugin: use the webpack "infrastructure logger" for logging, if present
manually checked output of errors and log level bugs against dashboard-js
Output from webpack 4:
Before
[bugsnag-build-reporter] Configuration error
[bugsnag-build-reporter] sourceControl must be an object containing { provider, repository, revision } (got "{
provider: 'github',
repository: 'https://github.com/bugsnag/dashboard-js',
revision: undefined
}")
[BugsnagSourceMapUploaderPlugin] uploading sourcemap for "http://localhost:8080/assets/app.826c2f1ffce9f1548c4c.js"
Error: HTTP status 401 received from upload API
at /Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/dist/Request.js:105:33
at ConcatStream.<anonymous> (/Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/node_modules/concat-stream/index.js:37:43)
at ConcatStream.emit (node:events:381:22)
at finishMaybe (/Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/node_modules/readable-stream/lib/_stream_writable.js:620:14)
at afterWrite (/Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/node_modules/readable-stream/lib/_stream_writable.js:466:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
error Command failed with exit code 1.
After:
<e> [BugsnagBuildReporterPlugin] Configuration error
<e> [BugsnagBuildReporterPlugin] sourceControl must be an object containing { provider, repository, revision } (got "{
<e> provider: 'github',
<e> repository: 'https://github.com/bugsnag/dashboard-js',
<e> revision: undefined
<e> }")
Error: HTTP status 401 received from upload API
at /Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/dist/Request.js:105:33
at ConcatStream.<anonymous> (/Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/node_modules/concat-stream/index.js:37:43)
at ConcatStream.emit (node:events:381:22)
at finishMaybe (/Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/node_modules/readable-stream/lib/_stream_writable.js:620:14)
at afterWrite (/Users/dan/dashboard-js/node_modules/@bugsnag/source-maps/node_modules/readable-stream/lib/_stream_writable.js:466:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
error Command failed with exit code 1.
Note the absence of [BugsnagSourceMapUploaderPlugin] uploading sourcemap for "http://localhost:8080/assets/app.826c2f1ffce9f1548c4c.js" as the webpack logger does not output log level.
If it was a warn it would output <w> [BugsnagSourceMapUploaderPlugin] uploading sourcemap for "http://localhost:8080/assets/app.826c2f1ffce9f1548c4c.js" (in yellow colour).
It might be worth reviewing the various levels used throughout the code.
In terms of unit-level coverage I think the first step would be to convert to jest
use the webpack infrastructure logger (if available) rather than outputting to the console directly so that webpack
--silent
mode is respected.Goal
--silent
option and our webpack plugins should respect thatwebpack --mode=production --profile --json > stats/stats.json
). This requires silent mode to be respected. Note: webpack 5 stats don't need piping as they are generated withnpx webpack --profile --json=compilation-stats.json
. See https://webpack.js.org/api/stats/Design
Use the webpack recommended way of handling logging in webpack 4 and 5 plugins. See https://v4.webpack.js.org/api/plugins/#logging and https://webpack.js.org/api/plugins/#logging
The logger returned with
getLogger
doesn't output anything to the console in the event of an error, sogetInfrastructureLogger
is used, as the output is more useful.BugsnagBuildReporterPlugin
will not use the webpack logger when a custom logger option is supplied.webpack <= 4.37 doesn't have the logging API so:
BugsnagBuildReporterPlugin
falls back to its built in logger (unless a custom option logger is supplied); andBugsnagSourceMapUploaderPlugin
falls back toconsole
(there is no custom logger option).Changeset
Testing
Output from webpack 4:
Before
After:
Note the absence of
[BugsnagSourceMapUploaderPlugin] uploading sourcemap for "http://localhost:8080/assets/app.826c2f1ffce9f1548c4c.js"
as the webpack logger does not output log level.If it was a warn it would output
<w> [BugsnagSourceMapUploaderPlugin] uploading sourcemap for "http://localhost:8080/assets/app.826c2f1ffce9f1548c4c.js"
(in yellow colour).It might be worth reviewing the various levels used throughout the code.
In terms of unit-level coverage I think the first step would be to convert to jest