Open Bug 1712678 Opened 3 years ago Updated 3 years ago

[devtools-rfc] Use a Logger instead of direct calls to console.log/warn/error in DevTools

Categories

(DevTools :: General, task)

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?

Component: Console → General

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:

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

You need to log in before you can comment on or make changes to this bug.