Closed Bug 1925003 Opened 2 years ago Closed 1 year ago

Log JavaScript errors and warnings through MOZ_LOG

Categories

(DevTools :: Console, enhancement)

enhancement

Tracking

(firefox137 fixed)

RESOLVED FIXED
137 Branch
Tracking Status
firefox137 --- fixed

People

(Reporter: ochameau, Assigned: ochameau)

References

Details

Attachments

(1 external file)

Bug 1828100 started displaying/recording all calls made to JavaScript console API through MOZ_LOG.
It is handy as you can now also start debugging JavaScript codebases via MOZ_LOG.
But it is quickly frustrating as you won't see any JavaScript error (JS exception, parsing errors) or warning (CSS, CORS, tracking protection, ...).

A simple action would be to simply MOZ_LOG all the the nsIConsoleMessage's managed by nsConsoleService.
We could then either reuse the console Log module name (to match the C++ class),
or rather introduce a new module name messages, page-messages, page-console, console (and rename console to console-api/js-console), page-errors-and-warnings, js-errors,...?

Naming this is a bit tricky as it can be either info, warning or errors.
It isn't solely about JavaScript execution, but can be about requests, css, cors, cookies,...

nsConsoleService actually process either nsIConsoleMessage (which doesn't expose much beyond a log level + string),
but also nsIScriptError (which exposes many other things, including a category).
We could possibly differentiate the two and use two distinct module names.
We could also especially differentiates the nsIScriptError's through their category.

My motivation to work on this is to provide an easy way for WebCompat to record a sampling or tracing profile, which would include page errors and notices. This is to me very high value and it sounds better to invest into exposing this via MOZ_LOG rather than introducing custom profiler markers. I would have similar naming issues, and this wouldn't benefit overall Firefox debugging through MOZ_LOG.

Note that such feature will make the following logs to stderr redundant, if not obsolete:
https://searchfox.org/mozilla-central/rev/3265b390bd5d08a5be520253ef71835bcb715f27/js/xpconnect/src/nsXPConnect.cpp#270-304

While opening bug 1925323, I realized that profiler and about:logging presets may align on some cases.
And I was wondering if that could be worth toggling about:logging modules from the profiler popup when we select a profiler preset that matches an about:logging preset.

Assignee: nobody → poirot.alex
Status: NEW → ASSIGNED
Pushed by apoirot@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/608544cf1593 [devtools] Log nsConsoleService messages through MOZ_LOG. r=padenot
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 137 Branch
Blocks: 1945901
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: