Closed Bug 1687553 Opened 5 years ago Closed 4 years ago

Allow to `dump` and `console.log` to `MOZ_LOG`

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
88 Branch
Tracking Status
firefox88 --- fixed

People

(Reporter: nalexander, Assigned: nalexander)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Use case first. I want to capture logs for multiple independent Gecko/Firefox invocations happening over time. That is, I'm going to run Firefox in a special background task/maintenance mode every X hours, and I want to be able to log each run. I want to capture a cumulative historical log. I need to be able to log at many different levels of the Gecko/Firefox stack, which means that capturing all output produced would be optimal. However, not all OS-level task scheduling APIs (e.g., Windows Task Scheduler, macOS launchd, etc) will allow to capture an ongoing historical log of this sort. Therefore, I want to use Gecko's internal logging mechanisms. Since we have so many the best I can do is try to use one of the lowest level mechanisms in Gecko.

In this new background task mode it's entirely reasonable to set browser.dom.window.dump.enabled all the time, so that console.log and friends end up in dump. I'd like to send dump output to MOZ_LOG as well, around https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/js/xpconnect/loader/mozJSComponentLoader.cpp#133. Because that API is used only from JS, I don't anticipate threading or re-entrancy issues. Since dump is unusual I don't think the overhead of an additional MOZ_LOG call is likely to be a performance bottleneck, but others may know better.

I'll note that it would be nice to have Log.jsm logs with a specified module (say Toolkit.Telemetry.*) end up in MOZ_LOG with a matching module, but that's a great deal more effort than the one-line change this ticket tracks.

Blocks: 1343676

By extension, this makes console.log and friends log to the MOZ_LOG
system when browser.dom.window.dump.enabled is true.

My immediate use case is capturing cumulative logs for the new
--backgroundtask ... mode that will be used to invoke maintenance
tasks when Firefox itself is not running.

This will lead to duplicate messages (from both the MOZ_LOG system and
fputs) when the MOZ_LOG system is not redirected but there's no
particular harm in that. In the future, we could not fputs when the
MOZ_LOG system will log the given message, but it seems better to
actually do the work to connect the Log.jsm and ConsoleAPI.jsm
systems to MOZ_LOG rather than continue to add work arounds.

Assignee: nobody → nalexander
Status: NEW → ASSIGNED
Attachment #9202246 - Attachment description: Bug 1687553 - Make `dump` log to MOZ_LOG system under module "JSDump". r?#xpcom-reviewers → Bug 1687553 - Make more `dump` implementations log to MOZ_LOG system under module "Dump". r?nika
Pushed by nalexander@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7beb3088eb78 Make more `dump` implementations log to MOZ_LOG system under module "Dump". r=xpcom-reviewers,nika
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 88 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: