Open Bug 2084142 Opened 1 month ago Updated 24 days ago

Match log module names regardless of case and special characters

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

ASSIGNED

People

(Reporter: dcarver, Assigned: dcarver)

References

(Blocks 1 open bug)

Details

Attachments

(1 external file)

Log module names currently have to be spelled exactly as in code, which causes two problems:

  • A wrong case in MOZ_LOG (or in a logging.<name> pref) silently configures a new module that nothing uses (bug 1266365): MOZ_LOG=nshttp:5 does not enable nsHttp.
  • Modules whose names contain spaces or punctuation, such as the JS console prefixes Login crypto or ML:OpenAIPipeline, cannot be configured at all, since MOZ_LOG uses , and : as separators (bug 2079145).

Proposal: match module names by a key made of the name in ASCII lowercase, without the characters other than letters, digits, _, - and .. So nshttp:5 sets nsHttp, and logincrypto:5 sets Login crypto. Rust module paths, which contain ::, keep matching exactly, as Rust does.

To keep the name of a module spelled as in code, configuration (from MOZ_LOG or the logging.<name> prefs) should no longer create modules: the settings for a module that does not exist yet are kept until code creates it, through a new LogModule::ConfigureModule. A name then never changes once the module exists, so readers on other threads need no synchronization. Rust module paths and opentelemetry are still created right away, because Rust and OpenTelemetry mirror their level and only log to them at that level.

In debug builds, a warning is printed when two differently spelled names map to the same module.

A wrong case in MOZ_LOG silently configured a module that nothing uses
(bug 1266365), and modules whose names contain spaces or punctuation, such as
the JS console prefixes "Login crypto" or "ML:OpenAIPipeline", couldn't be
configured at all (bug 2079145). Names now match by a key in ASCII lowercase
without those characters, except Rust module paths, which Rust matches
exactly.

Module configuration, from MOZ_LOG or the logging.<name> prefs, no longer
creates modules: what it sets for a module that doesn't exist yet waits until
code creates it. A module's name is then always spelled as in code, and never
changes once created, so readers on other threads need no synchronization.
Rust module paths and "opentelemetry" are still created right away, as Rust
and OpenTelemetry mirror their level and only log to them at that level.

Attachment #9665180 - Attachment description: WIP: Bug 2084142 - Match log module names regardless of case and special characters. r?#xpcom-reviewers → Bug 2084142 - Match log module names regardless of case and special characters. r?#xpcom-reviewers
See Also: → 2084279

Posting here because phabricator is down. I'll repost there too once it's up.

I also explored the stricter direction, in bug 2079145: rename the outliers, then make LogModule::Get reject invalid names. Coming back to it, Sqlite felt like a blocker. It names one logger per connection, built from the database file name and a per-file counter (Sqlite.sys.mjs). On my profile:

SQLite JSM (Connection ae96af60.sqlite#0)
SQLite JSM (Connection content-prefs.sqlite#0)
SQLite JSM (Connection domain_to_categories.sqlite#0)
SQLite JSM (Connection formhistory.sqlite#0)
SQLite JSM (Connection places.sqlite#0)
SQLite JSM (Connection places.sqlite#1)
SQLite JSM (Connection places.sqlite#2)
SQLite JSM (Connection places_semantic.sqlite#0)
SQLite JSM (Connection protections.sqlite#0)
SQLite JSM (Connection tabnotes.sqlite#0)

(SQLite JSM (ConnectionOpener), (ConnectionCloner) and (ConnectionWrapper) are fixed strings, so they can be renamed like the other outliers.)

Unlike the other outliers, a rename can't fix the per-connection names:

  • They carry runtime data, so there is no single name to rename them to.
  • They are usable today: Setting logging.SQLite JSM (Connection places.sqlite#0) = 5 in about:config sends a single connection's messages to MOZ_LOG. With this patch, MOZ_LOG=sqlitejsmconnectionplaces.sqlite0:5 does the same.

Would you consider this case an outlier as well?

Flags: needinfo?(jstutte)
Flags: needinfo?(emilio)

If that's the only outlier, yes... Marco do you know how useful that feature is it? Can the logger name be normalized in places?

Flags: needinfo?(emilio) → needinfo?(mak)
See Also: → 2084854

(In reply to Emilio Cobos Álvarez [:emilio] from comment #3)

If that's the only outlier, yes... Marco do you know how useful that feature is it? Can the logger name be normalized in places?

I'm not sure I get the full extend of the question, but it would be ok to put all logs under the same "prefix" and filter later per database/connection. The dbname:conn# was put there because it looked easy and IIRC it was not yet going through MOZ_LOG when it was added.
As far as each log has dbname:conn# to filter on, I don't mind about the prefix.
Surely the logging will be more verbose not being able to get only one specific dbname, but that's manageable.

Flags: needinfo?(mak)

I guess Marco answered.

Flags: needinfo?(jstutte)

Thank you!

I'm currently considering this:

  • Rename the prefix option of ConsoleInstanceOptions to logModule. It names the MOZ_LOG module and nothing else.
  • Add a new optional prefix that is only shown before messages and has no effect on logModule.
  • Add an ESLint rule that requires logModule to be a string literal MOZ_LOG accepts: only [A-Za-z0-9_.-], and not starting with a digit.

Sqlite would then be console.createInstance({ logModule: "Sqlite", prefix: "Connection places.sqlite#0", ... }). MOZ_LOG=Sqlite:5 would turn on every connection.

I found more non-trivial outliers while implementing comment 6, so I updated the plan to handle them. A local stack implements the new plan. It is not on Phabricator yet.

  • prefix is not renamed. Instead, logModule is added next to it. A console with a prefix and no logModule still uses the prefix as its module, as it does today. That use is deprecated, and a second ESLint rule, mozilla/console-prefix-requires-log-module, warns about it. This way, code that cannot move in the same push keeps working. That includes all 124 console.createInstance calls in comm-central.
  • Extensions that must run on several versions of Firefox, such as New Tab when it train-hops, can pass the same value as both logModule and prefix. Older versions ignore logModule and use the prefix as the module. Newer versions use logModule and do not print the prefix twice.

The non-trivial outliers carry run-time data in their module name. Each one moves to a single module, and the run-time part moves to prefix:

I believe this moves us in the right direction for bug 2077111: once every console names its module with a literal logModule, we can list all the js log modules statically.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: