[devtools-rfc] Use a Logger instead of direct calls to console.log/warn/error in DevTools
Categories
(DevTools :: General, task)
Tracking
(Not tracked)
People
(Reporter: jdescottes, Unassigned)
References
(Blocks 1 open bug)
Details
DevTools code usually directly calls console APIs to log.
When a specific log becomes frequent it can be annoying for users and they have no way to silence it (eg Bug 1712574).
Instead we could use a Logger that would support Log levels and could be driven by preferences (eg similar to what marionette/remote-agent does). The preference would describe the minimum level of log that should be logged. For reference, the marionette logger uses the following (ordered) list of log levels: "fatal" > "error" > "warn" > "config" > "debug" > "trace" > "info". We might reuse or use a simplified version (the ordering of the lower levels seems a bit random, config/debug/trace/info all feel on the same "level" and are rather categories IMO).
If a log becomes temporarily spammy, we could advise users to change the preference devtools.log.level
to a higher level.
Having logs enabled by default is a very valuable source of feedback, so if we have a Logger we should be careful about disabling them by default.
We could first implement a logger and gradually replace our console usage with it in DevTools, eventually adding a linter rule to prevent direct console API usage?
Reporter | ||
Updated•3 years ago
|
Reporter | ||
Comment 1•3 years ago
|
||
This was mentioned in the last devtools meeting. Quick summary of the feedback so far:
Existing Logging in DevTools
We already have a few "logging" solutions in DevTools, although the usage is very inconsistent.
Some examples:
dumpn
&dumpv
, driven byflags.wantLogging
&flags.wantVerbose
which are respectively linked to the preferencesdevtools.debugger.log
&devtools.debugger.log.verbose
(booleans)- the preference
devtools.dump.emit
will enable logs specific to the event emitter - Debugger's
reportException
https://searchfox.org/mozilla-central/rev/08f063f4c89d270fd809fc0325b5a9000ae87d63/devtools/client/debugger/src/utils/DevToolsUtils.js#7-10
They are somewhat mentioned in https://searchfox.org/mozilla-central/rev/e9eb869e90a8d717678c3f38bf75843e345729ab/devtools/docs/getting-started/development-profiles.md#50
We should review those existing logging mechanisms before introducing a new one and see how they would fit.
Log.jsm & Console.createInstance
Log.jsm has known issues (it is not e10s friendly), see https://bugzilla.mozilla.org/show_bug.cgi?id=1708532#c1
Console.createInstance
might be a good fit https://searchfox.org/mozilla-central/source/dom/webidl/Console.webidl#210-234
Comment 2•3 years ago
|
||
About existing pratices, I recently added logging via dump and a global boolean in the module:
https://searchfox.org/mozilla-central/rev/e9eb869e90a8d717678c3f38bf75843e345729ab/devtools/server/actors/network-monitor/network-observer.js#63-68
https://searchfox.org/mozilla-central/rev/e9eb869e90a8d717678c3f38bf75843e345729ab/devtools/server/actors/watcher/target-helpers/frame-helper.js#263-271
https://searchfox.org/mozilla-central/rev/e9eb869e90a8d717678c3f38bf75843e345729ab/devtools/server/connectors/js-window-actor/DevToolsFrameChild.jsm#97-103
Comment 3•3 years ago
|
||
May be also debugger actions logging:
https://searchfox.org/mozilla-central/source/devtools/client/debugger/test/mochitest/helpers.js#538
https://searchfox.org/mozilla-central/source/devtools/client/debugger/src/actions/utils/middleware/log.js#99-106
This one is controlled by a pref.
And the generic log middleware:
https://searchfox.org/mozilla-central/source/devtools/client/shared/redux/middleware/log.js#10-28
https://searchfox.org/mozilla-central/source/devtools/client/shared/redux/create-store.js#70
https://searchfox.org/mozilla-central/source/devtools/client/shared/redux/create-store.js#98
https://searchfox.org/mozilla-central/search?q=shouldLog%3A&path=&case=false®exp=false
This one seems to be used and preffed on by inspector and RDM, and disabled by Toolbox and Memory.
This one is controlled by a static boolean.
Description
•