#35355 Use atomics for determining whether trace logging is enabled
https://github.com/bitcoin/bitcoin/pull/35355 · · +347/-320 in 24 files, 12 commits · labels: Needs rebase · draft
Goal
- Avoid overhead on high-frequency code paths when trace or debug logging is disabled
- Simplify managing trace categories for node operators via the command line and RPC
Replaces the global and category-level map in the logging system with atomic bitmasks for debug and trace categories, making checks like ShouldDebugLog and ShouldTraceLog lock-free. In addition, replaces the -loglevel argument with -trace, updates the logging RPC interface to support trace categories with a deprecated output fallback, and makes Logger configuration access thread-safe.
Problem: Checking whether trace or debug logging is active for a category previously acquired a mutex or inspected complex log-level maps, adding overhead on high-frequency log paths when logging is disabled, while -loglevel was clunky to use alongside -debug.
Category: RPC / REST / ZMQ (#37 of 52)
P3 · new feature
- P3 because it expands the logging RPC to manage trace logging dynamically
- Changes to RPC output structures require careful deprecation handling
P3 because it expands the logging RPC to manage trace logging dynamically, though changes to RPC output structures require careful deprecation handling.
Membership: Directly alters the `logging` RPC method signature, behavior, and output structure, adding a trace parameter and -deprecatedrpc fallback.
Factors: security/stability 0, bug 0, performance 0, user value 2, leverage 0
Category: Utilities (logging, arguments, libraries) (#50 of 66)
P3 · speedup
- P3 because eliminating locks on disabled log checks offers minor performance hygiene
- Thread-safe log state checks provide small efficiency gains across busy threads
P3 because eliminating mutex locks when checking disabled log statements is a worthwhile performance hygiene improvement for multi-threaded operation, paired with internal Logger API cleanups.
Membership: Modifies core logging utilities in src/logging.{h,cpp} and src/util/log.h, altering concurrency and atomic state management.
Factors: security/stability 1, bug 0, performance 1, user value 1, leverage 1
Reviewability: Stale: Needs rebase
- Needs rebase due to merge conflicts with multiple open logging pull requests
- Stale with no author activity for nearly four months
The PR has merge conflicts with multiple open logging PRs (#35322, #35387) and has had no author activity for 118 days.
Author status: silent since 2026-05-22
Agreement: Crickets
- No reviews or comments received yet
- No contributor feedback since the author opened the draft
No reviews or concept comments received yet
The author opened the PR as a draft and force-pushed once; no other contributors have commented.
Review verdicts (DrahtBot): 0
Files
202 lines under test/bench/ci.
- src/logging.cpp +44/-84
- src/logging.h +67/-61
- src/test/logging_tests.cpp +40/-56
- src/rpc/node.cpp +64/-25
- test/functional/feature_logging.py +37/-22
- src/init/common.cpp +23/-30
- test/functional/rpc_misc.py +18/-5
- src/util/log.h +10/-6
- doc/release-notes-34038.md +13/-0
- src/kernel/bitcoinkernel.cpp +4/-7
- src/test/i2p_tests.cpp +6/-4
- doc/developer-notes.md +4/-5
- src/bench/logging.cpp +3/-3
- test/functional/test_framework/test_node.py +4/-1
- src/httpserver.cpp +2/-2
- src/test/util/setup_common.cpp +1/-2
- src/bitcoind.cpp +1/-1
- src/node/abort.cpp +1/-1
- src/qt/guiutil.cpp +1/-1
- src/rpc/client.cpp +2/-0
- src/rpc/server.cpp +1/-1
- src/wallet/sqlite.cpp +1/-1
- src/init.cpp +0/-1
- src/init/common.h +0/-1
Card
This PR optimizes the disabled-logging path by replacing the Logger category log level map and global level with atomic bitmasks, making ShouldDebugLog and ShouldTraceLog lock-free. It also deprecates -loglevel in favor of a simpler -trace startup flag and updates the logging RPC with trace controls and deprecation fallbacks. The change addresses multi-threaded lock overhead on disabled trace statements and simplifies the developer logging interface. It is currently in draft with merge conflicts and has received no external reviews.