Use atomics for determining whether trace logging is enabled #35355

pull ajtowns wants to merge 12 commits into bitcoin:master from ajtowns:202512-log-atomic changing 24 files +347 −320
  1. ajtowns commented at 12:56 AM on May 22, 2026: contributor

    Followup of #28318, #34038, and #34806 to simplify and optimize the logging-disabled path for LogTrace().

    Removes the global log level (m_log_level) and the unordered_map from category to level (m_category_log_levels) in favour of a single atomic<uint64_t> m_trace_categories, and reduces ShouldDebugLog and ShouldTraceLog to lock-free checks on a single atomic. Also makes Enabled() lock-free, to waste a little less time in the case where debugging is completely disabled.

    Does a bit of clean up as well:

    • guards m_file_path and provides accessors
    • makes other configuration variables atomic, rather than "write-before-createing-threads-then-treat-as-read-only"
    • consolidates duplicated functions (SetCategoryLogLevel, Enable/Trace/DisableCategory, WillLogCategory)
  2. DrahtBot commented at 12:56 AM on May 22, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35355.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34411 ([POC] Full Libevent removal by fanquake)
    • #33847 (kernel: Improve logging API by ryanofsky)
    • #33646 (log: check fclose() results and report safely in logging.cpp by cedwies)
    • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
    • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #17783 (common: Disallow calling IsArgSet() on ALLOW_LIST options by ryanofsky)
    • #17581 (refactor: Remove settings merge reverse precedence code by ryanofsky)
    • #17580 (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
    • #17493 (util: Forbid ambiguous multiple assignments in config file by ryanofsky)
    • #10102 (Multiprocess bitcoin by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • values indicates its status -> values indicate its status [subject-verb agreement; the current phrasing is grammatically incorrect]

    <sup>2026-05-22 03:12:38</sup>

  3. ajtowns commented at 1:00 AM on May 22, 2026: contributor

    I first mentioned this three years ago at #25203 (comment) and had originally included it in #28318 (comment) . This branch was also linked to in #34038 (review) Obviously conflicts with #35322.

  4. logging: replace -loglevel arg with -trace
    Previously, trace logging for a category was enabled by saying "-debug=net
    -loglevel=net:trace" and saying "-loglevel=net:trace" (without "-debug"
    or "-debug=net") would silently do nothing. Simplify this so that
    "-debug=net" enables debug logging for net and "-trace=net" enables
    both debug and trace logging for net.
    
    Note that "-nodebug" and "-notrace" only disable previous "-debug=xxx" and
    "-trace=yyy" arguments, so "-debug=mempool -trace=net -nodebug" will cancel
    "-debug=mempool", but will still include both debug and trace logs for net.
    d8b6710a03
  5. rpc: Update logging RPC to support trace level debugging
    Also changes the output format, to distinguish debug/trace levels.
    Provides `-deprecatedrpc=logging` if old output format is needed.
    
    Co-Authored-By: stickies-v <stickies-v@protonmail.com>
    7af81b5d38
  6. [doc] Release notes for user-visible logging changes 77ac0f81cd
  7. logging: replace global and category log levels with atomic int
    Since we have reduced how much log levels can be configured (error,
    warning and info are always logged; and only debug and trace levels can
    be disabled), we only need two bits per category to store the information.
    We can do this with two atomic ints, one for whether -debug is enabled,
    and the other for whether -trace is enabled.
    
    This allows `WillLogCategoryLevel` to avoid taking a mutex, potentially
    allowing for better performance in the event that multiple threads are
    running many LogDebug(..) statements over categories that do not have
    -debug enabled (or LogTrace/-trace).
    810352a390
  8. logging: Make sure BCLog::Logger members are atomic or guarded 5431316967
  9. logging: Make Enabled() lock-free
    Add m_any_print_callbacks as a cache for !m_print_callbacks.empty(),
    and make m_buffered atomic. Makes the Log functions almost completely
    free when logging is completely disabled (though unlike for LogDebug
    when the category is disabled, arguments are still evaluated).
    787f095f0c
  10. [move-only] logging: Move Logger member variables together b9b9d8ca33
  11. logging: Drop unused SetCategoryLogLevel(str,str) 4f259fd04c
  12. logging: Replace Enable/Trace/DisableCategory(str) with SetCategoryLogLevel(str, level) 60dacd0db5
  13. logging: Drop Enable/Trace/DisableCategory aliases 52f90febd5
  14. logging: Drop WillLogCategory* in favour of Logger::ShouldDebugLog and ShouldTraceLog 84dc8e4223
  15. util/log.h: Move internal functions into detail namespace 10e63dbb62
  16. ajtowns force-pushed on May 22, 2026
  17. DrahtBot added the label CI failed on May 22, 2026
  18. DrahtBot removed the label CI failed on May 22, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-22 22:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me