Reject C++ log module names that MOZ_LOG cannot parse at compile time
Categories
(Core :: XPCOM, task)
Tracking
()
People
(Reporter: dcarver, Assigned: dcarver)
References
(Blocks 2 open bugs)
Details
Attachments
(2 external files)
The rules for what makes a valid log module name are not written down anywhere. NSPRLogModulesParser accepts names that start with - or contain * anywhere, and nothing checks the names given to LazyLogModule, so a C++ module can be declared under a name that MOZ_LOG cannot configure. Bug 2084279 renamed one such module, 3pcbexception, which MOZ_LOG stopped reading at because of its leading digit.
Proposal:
- Define the valid names in one header in mozglue,
LogModuleName.h, with no parser in it, so any header can check a name. It providesIsValidLogModuleNameand the matching regexes:- A C++ name is a single segment of ASCII letters, digits,
_,-and., which doesn't start with a digit or-. That way a misplaced level or flag, such as5or-m, can't be mistaken for a module name. - A Rust module path or tracing target has two or more such segments separated by
::. The last one can be*, as inneqo_transport::*.
- A C++ name is a single segment of ASCII letters, digits,
- Make the
LazyLogModuleconstructorconsteval, so a name that isn't a valid C++ name fails the build. All existing names already pass.
The new MOZ_LOG parser (bug 2080769) checks module names with the same regexes, and the mozilla/valid-log-module ESLint rule (bug 2086992) applies the C++ form to the logModule of JS consoles.
Names created at run time through LogModule::Get, as from JS consoles or logging.<name> prefs, are not checked here. Bug 2079145 covers those.
| Assignee | ||
Comment 1•12 days ago
|
||
A log module name is either a C++ name, a single segment, or a Rust module
path or tracing target, segments separated by ::, the last of which can be
*. A segment is made of ASCII letters, digits, '_', '-' and '.', and doesn't
start with a digit or '-', so that a misplaced level or flag can't be mistaken
for a name.
This grammar is stricter than what NSPRLogModulesParser reads today, which
also takes names starting with '-' or containing '*' anywhere. It is meant to
be the grammar of the log module names in MOZ_LOG.
IsValidLogModuleName and the regexes of the log module names live in
LogModuleName.h, apart from any parser, so that a header can check a name
without bringing a parser in.
| Assignee | ||
Comment 2•12 days ago
|
||
The constructor of LazyLogModule is now consteval, so a name that isn't a
valid C++ log module name, as IsValidCppLogModuleName tells, fails the build.
Description
•