Closed Bug 2086657 Opened 25 days ago Closed 17 days ago

Allow console.createInstance to name its MOZ_LOG module separately from its prefix

Categories

(Core :: DOM: Core & HTML, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: dcarver, Assigned: dcarver)

References

(Blocks 2 open bugs)

Details

Attachments

(4 external files)

The prefix option of console.createInstance has two jobs. It names the MOZ_LOG module of the console, and it is the label printed before each message, in stdout and in the console events DevTools shows.

These jobs conflict:

  • A readable label, for example one containing a space or a colon, is often a module name that MOZ_LOG cannot parse, so the module cannot be configured with MOZ_LOG or the logging.* prefs. Bug 2084854 renames several such modules.
  • A label computed at run time (e.g. Places - <name> or MerinoClient [<name>]) creates a new module for each value, rather than one module that can be enabled as a whole.

Proposal: add a logModule option to console.createInstance that names the MOZ_LOG module, so that prefix can be just a label.

  • In stdout and in ConsoleEvent.prefix, each message is preceded by <logModule>: <prefix>: . Messages sent to MOZ_LOG only get the prefix, since MOZ_LOG already prints the module name. When both have the same value, the name is printed once.
  • A console created with a prefix and no logModule behaves as before: its prefix names the module. This keeps existing callers working, in the tree and outside it (e.g. comm-central). This use becomes deprecated.
  • A console with neither still logs to the console module.
  • Code that must run on several versions of Firefox, such as New Tab, which can train-hop, can pass the same value as logModule and prefix: older versions ignore logModule and use the prefix as the module.

The in-tree consoles then move from prefix to logModule, keeping the same module names.

Blocks: 2086676

The prefix option of console.createInstance has two jobs. It names the MOZ_LOG
module of the console, and it is the label printed before each message, in
stdout and in the console events DevTools shows. These jobs conflict: a
readable label, for example one containing a colon, is often a module name
MOZ_LOG cannot parse, and a label computed at run time creates a new module
for each value.

The new logModule option names the MOZ_LOG module, so the prefix can be just a
label. In stdout and in ConsoleEvent.prefix, each message is now preceded by
"<logModule>: <prefix>: ". Messages sent to MOZ_LOG only get the prefix,
since MOZ_LOG already prints the module name.

A console created with a prefix and no logModule behaves as before: its prefix
names the MOZ_LOG module. This keeps existing callers working, in the tree and
outside it (e.g. comm-central), until they move to logModule. This use is
deprecated.

Code that must run on several versions of Firefox can pass the same value as
logModule and prefix. Older versions ignore logModule and use the prefix as
the module. This version uses logModule as the module and doesn't print the
same name twice.

A console with neither a logModule nor a prefix still logs to the "console"
module.

Attachment #9670648 - Attachment description: WIP: Bug 2086657 - Add a logModule option to console.createInstance, separate from the prefix. r?#dom-core-reviewers → Bug 2086657 - Add a logModule option to console.createInstance, separate from the prefix. r?#dom-core-reviewers

The previous patch deprecates naming the MOZ_LOG module of a console with its
prefix alone. The consoles created with console.createInstance now give that
name as logModule instead. A console with a logModule and no prefix prints its
logModule before each message, as it printed its prefix, so these consoles
keep logging to the same modules, under the same label.

This patch is only the output of the following command, which is how to
regenerate it if it goes stale:

rg -l --glob '.{js,mjs,html,xhtml,jsx}' -g '!browser/extensions/newtab/' -g '!tools/lint/eslint/' 'console.createInstance(' .
| xargs sed -i ''
-e 's/(console.createInstance({[^}]
[^A-Za-z0-9_.$])prefix:/\1logModule:/'
-e '/console.createInstance({ *$/,/})/ s/([^A-Za-z0-9_.$"])prefix:/\1logModule:/'

The following patch renames by hand the prefixes this command does not reach.

The previous patch renames the prefix of the consoles to logModule where a
sed can. This one does it by hand where the sed cannot:

  • the options objects of NetworkGeolocationProvider and
    LoginHelper.createLogger,
  • the shorthand prefix of the URLBar logger,
  • the code examples and the text of the docs,
  • the comments that called the prefix the module name.

The MOZ_LOG module of a console created with console.createInstance is now
named by its logModule, and naming it with the prefix alone is deprecated.
Each console of New Tab now gets its module name as logModule, so that it
keeps logging to the same module.

New Tab can train-hop to a version of Firefox that ignores logModule and
names the module after the prefix, so its consoles keep their prefix until
the first version with logModule reaches Release. As their prefix is the
same as their logModule, it is not printed twice.

Blocks: 2086992
Attachment #9670665 - Attachment description: WIP: Bug 2086657 - Name the MOZ_LOG module of the consoles with logModule rather than prefix. r?#frontend-codestyle-reviewers → WIP: Bug 2086657 - Replace prefix: with logModule: in the console.createInstance calls, with an rg command. r?#frontend-codestyle-reviewers
Attachment #9670666 - Attachment description: WIP: Bug 2086657 - Name the MOZ_LOG module of the remaining consoles with logModule rather than prefix. r?#frontend-codestyle-reviewers → WIP: Bug 2086657 - Replace prefix: with logModule: by hand in the console.createInstance calls the rg command misses. r?#frontend-codestyle-reviewers
Attachment #9670667 - Attachment description: WIP: Bug 2086657 - Name the MOZ_LOG module of the New Tab consoles with logModule too. r?#home-newtab-reviewers → WIP: Bug 2086657 - Add logModule: alongside prefix: in the console.createInstance calls of New Tab. r?#home-newtab-reviewers
Pushed by dcarver@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/4c5bc49c2b96 https://hg.mozilla.org/integration/autoland/rev/eeb1e291743e Add a logModule option to console.createInstance, separate from the prefix. r=devtools-reviewers,ochameau
Attachment #9670665 - Attachment description: WIP: Bug 2086657 - Replace prefix: with logModule: in the console.createInstance calls, with an rg command. r?#frontend-codestyle-reviewers → Bug 2086657 - Replace prefix: with logModule: in the console.createInstance calls, with an rg command. r?#frontend-codestyle-reviewers
Attachment #9670666 - Attachment description: WIP: Bug 2086657 - Replace prefix: with logModule: by hand in the console.createInstance calls the rg command misses. r?#frontend-codestyle-reviewers → Bug 2086657 - Replace prefix: with logModule: by hand in the console.createInstance calls the rg command misses. r?#frontend-codestyle-reviewers
Attachment #9670667 - Attachment description: WIP: Bug 2086657 - Add logModule: alongside prefix: in the console.createInstance calls of New Tab. r?#home-newtab-reviewers → Bug 2086657 - Add logModule: alongside prefix: in the console.createInstance calls of New Tab. r?#home-newtab-reviewers
Attachment #9670666 - Attachment description: Bug 2086657 - Replace prefix: with logModule: by hand in the console.createInstance calls the rg command misses. r?#frontend-codestyle-reviewers → Bug 2086657 - Replace prefix: with logModule: by hand in the console.createInstance calls (manual changes). r?#frontend-codestyle-reviewers
Attachment #9670666 - Attachment description: Bug 2086657 - Replace prefix: with logModule: by hand in the console.createInstance calls (manual changes). r?#frontend-codestyle-reviewers → Bug 2086657 - Replace prefix: with logModule: in the console.createInstance calls (manual changes). r?#frontend-codestyle-reviewers
Attachment #9670665 - Attachment description: Bug 2086657 - Replace prefix: with logModule: in the console.createInstance calls, with an rg command. r?#frontend-codestyle-reviewers → Bug 2086657 - Replace prefix: with logModule: in the console.createInstance calls (Automatic fixes). r?#frontend-codestyle-reviewers
Pushed by dcarver@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/d6e6e4211833 https://hg.mozilla.org/integration/autoland/rev/074a8827c5e2 Replace prefix: with logModule: in the console.createInstance calls (Automatic fixes). r=saschanaz,search-reviewers,fxview-reviewers,urlbar-reviewers,daleharvey,timhuang,jsudiaman,frontend-codestyle-reviewers,Standard8
Status: ASSIGNED → RESOLVED
Closed: 17 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
Pushed by dcarver@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/a4609c02098a https://hg.mozilla.org/integration/autoland/rev/5bf67a1aeece Replace prefix: with logModule: in the console.createInstance calls (manual changes). r=frontend-codestyle-reviewers,urlbar-reviewers,daleharvey,Standard8 https://github.com/mozilla-firefox/firefox/commit/a12ca65deb44 https://hg.mozilla.org/integration/autoland/rev/659527c7414d Add logModule: alongside prefix: in the console.createInstance calls of New Tab. r=mconley
See Also: → 2090853
See Also: → 2091043
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: