bugsnag / webpack-bugsnag-plugins

Webpack plugins for common BugSnag actions.
MIT License
32 stars 29 forks source link

use webpack for logging #55

Closed djskinner closed 3 years ago

djskinner commented 3 years ago

use the webpack infrastructure logger (if available) rather than outputting to the console directly so that webpack --silent mode is respected.

Goal

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, 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:

Changeset

Testing

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