Add ESLint rules to check the MOZ_LOG module names of consoles
Categories
(Developer Infrastructure :: Linting and Formatting: JavaScript, task)
Tracking
(Not tracked)
People
(Reporter: dcarver, Assigned: dcarver)
References
(Depends on 1 open bug, Blocks 3 open bugs)
Details
Attachments
(12 external files, 1 obsolete file)
Bug 2086657 adds a logModule option to console.createInstance to name the MOZ_LOG module of a console, separately from its prefix, which is only printed. Bugs 2084854 and 2086676 fix the modules whose names MOZ_LOG cannot parse. Nothing stops new ones from being added.
ESLint can check this:
- A rule requiring the
logModuleto be a string literal made only of the characters MOZ_LOG reads in a module name: ASCII letters, digits,_,-and., not starting with a digit. A literal also lets every JS module be listed from the source, which the meta bug 2077111 asks for. Only theprefixmay have parts known at run time. - A rule warning about a console with a
prefixand nologModule, as naming the module with the prefix alone is deprecated by bug 2086657. It would only warn, as code outside the tree still relies on it.
A few consoles do not give a string literal as their module name, so they need to change rather than have exceptions to the rule:
LoginHelper.createLogger, theSQLiteStoreBasesubclasses andGeckoViewUtils.initLoggingConsolecreate the console in a helper, from a name they are given. Each caller should create its console with a literallogModuleinstead.AboutHomeStartupCacheuses a constant, and thetest_console_shouldLog.jsandtest_logFilePrefReset.jstests use a constant or build the name at run time.
The names of their modules do not change.
The logging docs (xpcom/docs/logging.md and toolkit/docs/javascript-logging.md) should also say that the logModule names the MOZ_LOG module, and how to find the JS modules. The Searchfox query in xpcom/docs/logging.md that claims to list all modules only finds the C++ ones.
Comment 1•24 days ago
|
||
I'm not convinced that an ESLint rule is the best way to resolve this - it would effectively be checking the arguments to a function, which the function itself should be checking. If we add this then we'll be encoding business logic in a linter, which doesn't seem right.
| Assignee | ||
Comment 2•24 days ago
|
||
Thanks for your feedback. The minimum requirement is that every MOZ_LOG module created from JS (and elsewhere) can be listed from the source, which bug 2077111 needs. For example, about:logging could then show all the available modules, including those whose code hasn't run yet. That requires logModule to be a string literal at the call site. This is a property of the source code, not of the value passed at run time, so only a tool that reads the source can check it, and ESLint already reads every call site and is what developers already run.
A run-time check could also help, in LogModule::Get (bug 2079145), but it would be stripped from release builds.
Do you see a better way to meet this requirement?
Comment 3•24 days ago
|
||
If we want to require that module names be static literals then that is something best checked by the linter and at that point it's reasonable to assert that the literal is of the expected form. I think this is less likely to be missed than a console message at runtime.
Comment 4•24 days ago
|
||
Okay, let's go with the linter for now. In some ways I'd like this to be encodable via TypeScript, unfortunately it doesn't look like that is easily possible (and we haven't got TypeScript enabled everywhere yet).
| Assignee | ||
Comment 5•23 days ago
|
||
Using a string literal rather than the LOG_NAME property, which nothing
else reads, lets the mozilla/valid-log-module ESLint rule of a following
patch check it. The name of the log module does not change.
| Assignee | ||
Comment 6•23 days ago
|
||
Using a string literal rather than a constant lets the mozilla/valid-log-module ESLint rule of a following patch check it.
| Assignee | ||
Comment 7•23 days ago
|
||
Using a string literal for each, rather than building it from the MOZ_LOG level of the case, lets the mozilla/valid-log-module ESLint rule of a following patch check it. The test still checks the same modules, with the same maximum log levels.
Updated•18 days ago
|
| Assignee | ||
Comment 8•17 days ago
|
||
Its callers now create their console themselves, so that its logModule
is a string literal the mozilla/valid-log-module ESLint rule of a
following patch can check. Since bug 2087579, createLogger only gave
the console signon.loglevel as its maxLogLevelPref, which each caller
now gives itself. The names of the log modules do not change.
| Assignee | ||
Comment 9•17 days ago
|
||
Creating the console in each store, rather than in SQLiteStoreBase from
the logPrefix and logLevelPref getters, makes its logModule a string
literal, that the mozilla/valid-log-module ESLint rule of a following
patch can check. The createLog method replaces the logLevelPref getter.
The names of the log modules do not change.
| Assignee | ||
Comment 10•17 days ago
|
||
Creating the console at the call site, rather than in
GeckoViewUtils.initLoggingConsole from the tag it is given, makes its
logModule a string literal, that the mozilla/valid-log-module ESLint
rule of a following patch can check. The name of the
GeckoView.IPProtection log module does not change.
| Assignee | ||
Comment 11•17 days ago
|
||
The MOZ_LOG module of a console created with console.createInstance is
named by its logModule. The new mozilla/valid-log-module rule requires
the logModule to be a string literal made only of the characters MOZ_LOG
reads in a module name, so that every module can be configured, and
listed from the source. A prefix may have parts only known at run time.
So that it can read the logModule, the rule also requires the options of
console.createInstance, when given, to be an object literal written in the
call.
The rule also rejects a logModule named like a MOZ_LOG option such as
"sync", which MOZ_LOG reads as the option instead of the module.
| Assignee | ||
Comment 12•17 days ago
|
||
Without a logModule, the prefix of a console created with
console.createInstance names its MOZ_LOG module, which is deprecated and
only kept for compatibility, as code outside the tree still relies on
it. The new mozilla/console-prefix-requires-log-module rule warns about
a prefix with no logModule next to it. It is only a warning, so that
code which has not moved to logModule yet still passes the lint. The two
consoles that test this compatibility disable the rule.
| Assignee | ||
Comment 13•17 days ago
|
||
The logModule of a console names its MOZ_LOG module and must be a string
literal that MOZ_LOG can parse, while its prefix is only printed. The
docs now say so, and how to find the modules of JavaScript.
| Assignee | ||
Comment 14•17 days ago
|
||
MOZ_LOG is now read by the parser of mozglue/misc/LogModulesParser.h. Like
it, the rule rejects a logModule starting with "-", and one named like a
MOZ_LOG option such as "sync" whatever its case, since the parser compares
the options without case.
| Assignee | ||
Comment 15•13 days ago
|
||
The test creates its consoles from options that are spread into
console.createInstance, so their logModule is not a string literal in
the call. Write each console.createInstance call out with its
logModule as a string literal, so that the mozilla/valid-log-module
ESLint rule of a following patch can check it.
| Assignee | ||
Comment 16•12 days ago
|
||
Updated•11 days ago
|
| Assignee | ||
Comment 17•10 days ago
|
||
Give the console of TaskbarTabsPinBase the TaskbarTabs logModule, as the
other consoles of browser/components/taskbartabs/ have. The
mozilla/console-prefix-requires-log-module rule of the next patch then
has nothing to warn about in this file.
Updated•10 days ago
|
Updated•10 days ago
|
Updated•4 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Updated•3 days ago
|
Comment 18•2 days ago
|
||
Comment on attachment 9674864 [details]
WIP: Bug 2086992 - Check logModules against the new MOZ_LOG parser in the valid-log-module ESLint rule. r?#frontend-codestyle-reviewers
Revision D339982 was moved to bug 2080769. Setting attachment 9674864 [details] to obsolete.
Description
•