Review report

core: PR #34778

1 minor finding · 4 suggestions

Findings

Link

[minor] · -loglevelalways omits the category on Info, Warning, and Error lines

With -loglevelalways=1, Info lines have no prefix and Warning/Error lines omit all:, contrary to the option’s help text.

Location: src/logging.cpp:359 (head).

Details and suggested fix

GetLogPrefix clears has_category for every level above Debug, even when m_always_print_category_level is set. With -loglevelalways=1, the base printed [all:info], [all:warning], and [all:error]; this version prints no prefix for Info and prints [warning] and [error] for the other levels. The help text still says the option always prepends a category and level. Default output is unchanged, and the change affects log formatting only. To hide real categories at high levels while honoring the option, map the category to ALL rather than clearing has_category. Add a test with the option enabled. If the changed output is intentional, update the help text and add a release note.


Optional improvements

Link

[suggestion] · Disabled Debug and Trace calls acquire the logger mutex

Every Debug or Trace call for a disabled category now locks m_cs, adding hot-path contention that the base avoided; no availability impact is established.

Location: src/logging.cpp:625 (head).

Details and suggested fix

hooks::ShouldLog calls logger.Enabled() before checking the category, and Enabled() takes m_cs. In the base, the category mask could reject Debug and Trace calls before any lock was acquired. Now, calls such as the per-message LogDebug(BCLog::NET, ...) in ProcessMessage lock the global logger mutex even when NET is disabled. Logging holds the same mutex while writing to the console, callbacks, and debug log file, so these calls can wait behind unrelated output. The cost has not been measured. Check the category and level before calling Enabled(): return logger.WillLogCategoryLevel(static_cast<BCLog::LogFlags>(category), level) && logger.Enabled();. This preserves the result while allowing disabled categories to return without locking.


Link

[suggestion] · Category masks and integers pass the logging category parameter

A masked category or integer now compiles, but can reach an assertion when logging is enabled; no current caller does this.

Location: src/util/log.h:173 (head).

Details and suggested fix

GetContext(Category) accepts a uint64_t, so it also accepts integers and OR-ed LogFlags masks. In the base, the logging function required a BCLog::LogFlags, and a mask such as NET | HTTP did not implicitly convert to that enum, so the call failed to compile. Now the call compiles; if either category is enabled, GetLogPrefix passes the mask to LogCategoryToStr, which asserts that it is a single named category. No current caller passes a mask or integer, so this is a lost compile-time check, not a crash reachable through current callers. Change the overload to accept BCLog::LogFlags to restore the compile-time rejection.


Link

[suggestion] · Argument-evaluation test never enables the category

The Debug and Trace assertions pass at both base and head, so they do not test whether the new logger-disabled gate skips argument evaluation.

Location: src/test/logging_tests.cpp:592 (head).

Details and suggested fix

LogSetup disables all categories, and logging_arg_evaluation never enables NET again. Its Debug and Trace checks therefore pass whether the logger is enabled or disabled, and they pass at the base as well. The test misses both the new behavior, where an enabled category with logging disabled should skip argument evaluation, and the positive case, where enabling both should evaluate the arguments. Enable BCLog::NET and set the log level to Trace inside the loop. Expect counter == 2 when enable_logger is true and 0 when it is false. Optionally, also check that util::log::ShouldDebugLog(BCLog::NET) == enable_logger.


Link

[suggestion] · Developer notes do not explain how to pass ratelimit = false

The documentation names a rate-limit option but gives no usable example, unlike the text it replaced.

Location: doc/developer-notes.md:818 (head).

Details and suggested fix

The Logging section documents only LogInfo, LogDebug, LogTrace, LogWarning, LogError, and LogWarnThenDebug, whose options are fixed. The new text says rate limiting can be disabled with the ratelimit = false option, but does not explain that LOG_EMIT accepts options or show its required parenthesized designated-initializer syntax. Since util/log.h directs readers to this section, add a concrete example matching the UpdateTipLog call, such as LOG_EMIT((.level = util::log::Level::Info, .ratelimit = false), "UpdateTip: new best=%s ...", ...).


Coverage details