Skip to content
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

More control over enabling/disabling debug logging #1619

Closed
jiayihu opened this issue Sep 4, 2018 · 13 comments · Fixed by #2282
Closed

More control over enabling/disabling debug logging #1619

jiayihu opened this issue Sep 4, 2018 · 13 comments · Fixed by #2282
Labels
Developer Experience Related to ease of use for developers.
Milestone

Comments

@jiayihu
Copy link

jiayihu commented Sep 4, 2018

Currently, it's not possible to disable debugging logs in localhost, and it's a very annoying experience. It would be nice to allow adding a debug option to GenerateSW configuration and, since we're here, customising log level should also be possible.

@jeffposnick
Copy link
Contributor

The general approach to changing the log level is at https://developers.google.com/web/tools/workbox/guides/configure-workbox#configure_log_levels

This is fairly straight forward when using InjectManifest mode, since you "own" the code for your service worker file.

If you'd like to do the same in GenerateSW mode, I'd recommend putting workbox.core.setLogLevel(workbox.core.LOG_LEVELS.silent); into a standalone JavaScript file, and then reference it in the importScripts option when configuring GenerateSW.

We're of the opinion that the logs can catch a lot of problems during the development cycle that you'd otherwise run into during production, and given that there is a workaround, making it much easier than that to disable them on localhost when using GenerateSW is not a priority.

@ImanMh
Copy link

ImanMh commented Mar 10, 2019

@jeffposnick What do you think about adding a debug or logLevel option to workbox-webpack-plugin ?

@ImanMh
Copy link

ImanMh commented Mar 10, 2019

@jeffposnick and by the way, LOG_LEVELS is undefined cause it's not exported.
https://github.com/GoogleChrome/workbox/blob/master/packages/workbox-core/index.mjs

@bam-tbf
Copy link

bam-tbf commented Apr 22, 2019

We have the reverse issue: We would like to show workbox debug messages on a deployed server, and this is also not possible. Please reopen this and add debug level configuration as a option regardless of host.

@philipwalton
Copy link
Member

@ImanMh, LOG_LEVELS was removed in v4. You can see this mentioned under the breaking changes section of the v4 release notes:

Workbox log levels have been removed since now all developer tools support filtering visible logs by level. As a result, workbox.core.setLogLevel(), workbox.core.logLevel, and workbox.core.LOG_LEVELS have all been removed. [#1831]

@jeffposnick's comment above was made before v4 was released, but everything else he said is still true today. You can see the debug level logs by configuring devtools to show them.

Screen Shot 2019-04-23 at 10 04 15 AM

@jrgtt
Copy link

jrgtt commented Jun 13, 2019

Is there a workaround to remove those logs if you're using firefox? Workbox messages polute the console, this LOG_LEVEL was actually a pretty neat feature.

@getkey
Copy link

getkey commented Aug 10, 2019

It's possible to turn off some messages but not all of them (see screenshot).
Screenshot from 2019-08-10 18-33-16

The developer experience is extremely poor because of this. The workaround I found is to develop on 127.0.0.1 instead of localhost.


@JRigotti the log levels on Firefox are on the top left of the console, but as I explained before they don't remove absolutely everything.
Screenshot from 2019-08-10 18-36-50

@a7madgamal
Copy link

please give us a way to prevent all this noise in the devtools

@jeffposnick jeffposnick changed the title Allow to configure logging in workbox-webpack-plugin More control over enabling/disabling debug logging Nov 20, 2019
@jeffposnick jeffposnick added the Developer Experience Related to ease of use for developers. label Nov 20, 2019
@jeffposnick jeffposnick reopened this Nov 20, 2019
@jeffposnick
Copy link
Contributor

We're re-opening this issue due to continued feedback from the community asking for alternatives.

In Workbox v5, this debug logging is enabled/disabled based on the value of process.env.NODE_ENV at the time the Workbox bundles are created. I understand that there might be scenarios in which you're using a development bundle but still want to be able to toggle Workbox's logging on and off on demand, via a runtime call to something like workbox.core.setConfig().

(There are a number of service worker "gotchas" that the debug logging helps you avoid, and I feel pretty strongly that we should keep logs enabled by default for development builds until someone takes the affirmative step of disabling them.)

@jeffposnick jeffposnick added this to the v5 milestone Nov 20, 2019
@jeffposnick
Copy link
Contributor

jeffposnick commented Nov 21, 2019

The mechanics of this are a little tricky in v5, when folks are pulling in specific pieces of the Workbox runtime and won't necessarily have direct access to a hypothetical method like workbox.core.disableDevLogs().

So we're going to go ahead with an approach that relies on a global boolean variable, (tentatively self.__WB_DISABLE_DEV_LOGS ) which can then be toggled at runtime as needed. We'll also support an option for generateSW (tentatively disableDevLogs) which will allow you to automatically set an initial value for this boolean.

We're still, by default, going to enable the logs, so you'd have to specifically disable them, rather than the other way around.

@StephanBijzitter
Copy link
Contributor

What about production builds, though? I'd like to be able to include the logs on our staging environments (and only keep them turned off for the live environment). I tried setting mode: 'development' for InjectManifest (webpack plugin), but that seems to have absolutely no effect.

@jeffposnick
Copy link
Contributor

Workbox uses process.env.NODE_ENV to enable/disable the execution of verbose logging.

When using the InjectManifest webpack plugin, the NODE_ENV setting from the parent compilation's mode should be inherited, i.e. https://webpack.js.org/guides/production/#specify-the-mode

@sneakyfildy
Copy link

Just in case, filtering workbox using console filters seems to do not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Related to ease of use for developers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants