Allow console.createInstance to name its MOZ_LOG module separately from its prefix
Categories
(Core :: DOM: Core & HTML, enhancement)
Tracking
()
| 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_LOGor thelogging.*prefs. Bug 2084854 renames several such modules. - A label computed at run time (e.g.
Places - <name>orMerinoClient [<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
prefixand nologModulebehaves 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
consolemodule. - Code that must run on several versions of Firefox, such as New Tab, which can train-hop, can pass the same value as
logModuleandprefix: older versions ignorelogModuleand use the prefix as the module.
The in-tree consoles then move from prefix to logModule, keeping the same module names.
| Assignee | ||
Comment 1•24 days ago
|
||
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.
Updated•24 days ago
|
| Assignee | ||
Comment 2•24 days ago
|
||
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.
| Assignee | ||
Comment 3•24 days ago
|
||
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.
| Assignee | ||
Comment 4•24 days ago
|
||
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.
Updated•18 days ago
|
Updated•17 days ago
|
Updated•17 days ago
|
Updated•17 days ago
|
Updated•17 days ago
|
Updated•17 days ago
|
Updated•17 days ago
|
Updated•17 days ago
|
Updated•17 days ago
|
Comment 7•17 days ago
|
||
| bugherder | ||
Comment 8•16 days ago
|
||
| bugherder | ||
Comment 10•15 days ago
|
||
| bugherder | ||
Description
•