#34778 logging: rewrite macros to enforce restrictions at compile-time, improve efficiency and usability
https://github.com/bitcoin/bitcoin/pull/34778 · · +275/-113 in 6 files, 6 commits · labels: none
Goal
- Catch misuse of logging categories at compile time with clear error messages
- Make argument evaluation consistent and avoid formatting overhead when logging is disabled
Refactors the logging macros in util/log.h to consolidate internal macro logic into a single LOG_EMIT macro taking compile-time options. Replaces runtime checks and macro expansion errors with static assertions for required or forbidden logging categories, skips argument formatting when logging is disabled, and removes the unused Entry::should_ratelimit field in favor of an options struct.
Problem: Logging macros previously had duplicated logic with inconsistent argument evaluation semantics across log levels and produced opaque compiler errors when category arguments were misused.
Category: Utilities (logging, arguments, libraries) (#45 of 66)
P3 · cleanup
- P3 because benefits are developer-facing cleanups and minor logging efficiency gains.
- Clearer compile-time diagnostics help developers catch category misuses earlier.
Clear compile-time error improvements and consistent argument handling across logging macros. Author notes: 'eliminating inconsistencies, improving efficiency, and producing clearer compiler errors when called incorrectly'. The benefits are entirely developer-facing cleanups and minor fuzzing efficiency gains, fitting P3.
Membership: Directly rewrites logging macros in src/util/log.h and alters logging dispatch in src/logging.cpp.
Factors: security/stability 0, bug 1, performance 1, user value 0, leverage 1
Reviewability: Stale: Author silent
- Author has been silent for several months with unaddressed objections and a standing Concept NACK
The author has been silent for over 110 days, exceeding the project inactivity threshold, with unaddressed objections and a standing Concept NACK.
Author status: silent since 2026-05-26
Open concerns:
- ajtowns issued a Concept NACK against reintroducing a generic logging macro interface.
- maflcko expressed concern that exposing a flexible macro with designated initializers allows bypassing level restrictions, weakens source-location tracking, and harms code greppability.
- sedited questioned keeping the PR open after months of inactivity and unresolved NACK.
Resolved concerns:
- Tests were added to explicitly pin argument evaluation behavior across disabled and enabled loggers.
Agreement: Disputed
- Significant pushback against the macro design with prolonged author inactivity
- Concept NACK against reintroducing a generic logging macro interface (ajtowns)
- Unaddressed objection: flexible macro risks bypassing log levels and harms greppability (maflcko)
- Questioned keeping the PR open given prolonged inactivity and the unresolved NACK (sedited)
Concept NACK from ajtowns and reservations from maflcko regarding macro design, unanswered since May.
ajtowns registered an explicit Concept NACK opposing the macro reintroduction, while maflcko objected to exposing low-level parameter options that could encourage brittle logging wrappers. The author defended the cleanup but has not resumed discussion in months.
- ajtowns: 'Concept NACK to reintroducing a generic LogPrint.'
- maflcko: 'not sure about using the internal/hidden macro here... I don't see the point in allowing all of this, if there is no reason for it.'
- sedited: 'This has not received review for half a year, has a N-A-C-K and maflcko's last comment wasn't replied to. Maybe this should be closed at this point?'
Review verdicts (DrahtBot): 0 -1
- Concept NACK: ajtowns
Dependencies
Files
137 lines under test/bench/ci.
- src/util/log.h +136/-63
- src/test/logging_tests.cpp +116/-21
- src/logging.cpp +17/-23
- src/validation.cpp +3/-2
- src/logging.h +2/-2
- doc/developer-notes.md +1/-2
Card
PR #34778 refactors util/log.h to unify logging macros under a single compile-time options macro (LOG_EMIT). It provides explicit static assertions when category arguments are missing or forbidden, skips format string evaluation when logging is disabled, and cleans up rate-limiting parameter plumbing. The change is an internal developer utility refactor, but it faces an unwithdrawn Concept NACK from ajtowns and pushback from maflcko regarding macro design and greppability. The author has been silent for over 110 days, making further review unadvisable until the approach dispute is resolved.