-
Notifications
You must be signed in to change notification settings - Fork 29
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
use webpack for logging #55
Conversation
source-map-uploader-plugin.js
Outdated
|
||
const chunkToSourceMapDescriptors = chunk => { | ||
// find .map files in this chunk | ||
const maps = chunk[webpackMajorVersion >= 5 ? 'auxiliaryFiles' : 'files'].filter(file => /.+\.map(\?.*)?$/.test(file)) | ||
|
||
if (!publicPath) { | ||
console.warn(`${LOG_PREFIX} ${PUBLIC_PATH_WARN}`) | ||
logger.warn(`${LOG_PREFIX} ${PUBLIC_PATH_WARN}`) |
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.
This needs a little more work as webpack already adds the prefix so we need to omit it when the webpack logger is used
9dee51f
to
d793f93
Compare
: {} | ||
) | ||
|
||
reportBuild(this.build, options) |
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.
This means that for webpack >= 4.37 the logLevel documented option does nothing because the built-in logger is not used. This also applies (as it did before) if you pass a custom logger. Not sure if this is worth documenting?
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.
I think that's fine. We should update the docs to say which cases it works in.
rather than outputting to the console directly so that the plugins respect webpack silent mode
d793f93
to
71fbbab
Compare
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.
It would seem odd to have to use a "warn" log to say that an upload was successful. Can you use .info()
instead?
: {} | ||
) | ||
|
||
reportBuild(this.build, options) |
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.
I think that's fine. We should update the docs to say which cases it works in.
5b317d0
to
83062c3
Compare
@@ -91,7 +93,7 @@ class BugsnagSourceMapUploaderPlugin { | |||
|
|||
const sourceMaps = stats.chunks.map(chunkToSourceMapDescriptors).reduce((accum, ds) => accum.concat(ds), []) | |||
parallel(sourceMaps.map(sm => cb => { | |||
console.log(`${LOG_PREFIX} uploading sourcemap for "${sm.url}"`) | |||
logger.info(`${logPrefix}uploading sourcemap for "${sm.url}"`) |
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.
Changed to info so that it shows in the webpack logger output
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.
Output shows as:
<i> [BugsnagSourceMapUploaderPlugin] uploading sourcemap for "http://localhost:8080/assets/slack.826c2f1ffce9f1548c4c.js"
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