The bitcoinkernel library (#27587) exposes functionality to interface with kernel logging. This includes registering callbacks for log statements, level/category filtering, string formatting options, and more.
This PR improves kernel logging by making it struct-based instead of string-based. Rather than adding this functionality onto an already large BCLog::Logger class, the PR first separates log generation (i.e. producing the log message via LogInfo(msg)) from log consumption (i.e. formatting, ratelimiting, printing the message) by moving all log generation code to util/log.h. While not strictly necessary for adding struct-based logging, it better separates concerns and is a prerequisite for follow-up work in #34374 that completely removes kernel’s dependency on logging.cpp.
Approach:
-
Separate log generation: Add a minimal
util::log::Dispatcherthat is used to generate logs, and forwards struct-based log entries to registered callbacks. No formatting, rate-limiting, or output handling - that’s the consumer’s responsibility. -
Register
BCLog::Loggeron Dispatcher: Register a callback on the global Dispatcher to receive entries and handle node-specific concerns (formatting, rate-limiting, file output) without changing most of its logic. Route logging macros through this global dispatcher. -
Update bitcoinkernel C API: Replace the string-based callback with
btck_LogEntrycontaining full metadata and removebtck_LoggingOptionsand related functions.
Note: with this change, bitcoinkernel logging callbacks are no longer routed through BCLog::Logger. This means that they are no longer buffered (i.e. log messages produced before a logging callback is registered) are dropped, and there is no longer a need for btck_logging_disable. In practice, this means users can no longer see the log message produced during the static context initialization.
Carve-out of #34374 to narrow the focus while maintaining tangible benefits (i.e. having struct-based logging).