logging: More fully remove libevent log category #35597

pull ryanofsky wants to merge 1 commits into bitcoin:master from ryanofsky:pr/logevent changing 5 files +42 −46
  1. ryanofsky commented at 3:37 PM on June 24, 2026: contributor

    Libevent log category was partially removed in 39e9099da59, and this commit extends that with the following changes:

    • Stops showing libevent in the list of supported log categories in bitcoind -help and bitcoin-cli help logging output.
    • Stops returning "libevent": false in logging RPC output.

    It's not good to treat libevent as a supported log category when it can't be enabled and trying to enable it results in warnings.

    There's also no need to define an unused LIBEVENT constant value and keep more complicated logic for dealing with deprecated log categories, so this change also simplifies code internally.

  2. logging: More fully remove libevent log category
    Libevent log category was partially removed in 39e9099da59, and this
    commit extends that with the following changes:
    
    - Stops showing libevent in the list of supported log categories in
      `bitcoind -help` and `bitcoin-cli help logging` output.
    
    - Stops returning `"libevent": false` in `logging` RPC output.
    
    It's not good to treat libevent as a supported log category when it
    can't be enabled and trying to enable it results in warnings.
    
    There's also no need to define an unused LIBEVENT constant value and
    keep more complicated logic for dealing with deprecated log categories,
    so this change also simplifies code internally.
    
    Co-authored-by: David Gumberg <davidzgumberg@gmail.com>
    Co-authored-by: l0rinc <pap.lorinc@gmail.com>
    3765b428d1
  3. DrahtBot commented at 3:37 PM on June 24, 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/35597.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK l0rinc, pinheadmz, sedited
    Stale ACK davidgumberg

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35587 (Remove boost as a unit test runner by rustaceanrob)
    • #34038 (logging: replace -loglevel with -trace, expose trace logging via RPC by ajtowns)

    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-->

  4. in src/logging.cpp:136 in d38170a4eb outdated
     132 | @@ -133,11 +133,6 @@ void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
     133 |  bool BCLog::Logger::EnableCategory(std::string_view str)
     134 |  {
     135 |      if (const auto flag{GetLogCategory(str)}) {
     136 | -        if (*flag & DEPRECATED){
    


    l0rinc commented at 5:38 PM on June 24, 2026:

    davidgumberg commented at 11:40 PM on June 24, 2026:

    Isn't this still true after this PR?


    l0rinc commented at 12:12 AM on June 25, 2026:

    Maybe, I wasn't sure what will be removed in a future version means when this PR already removes it - @ryanofsky?


    davidgumberg commented at 1:37 AM on June 25, 2026:

    If a user provides a nonexistent debug option bitcoind refuses to start, e.g.:

    $ bitcoind -debug=spiders
    Error: Unsupported logging category -debug=spiders.
    

    In this PR and on master, -debug=libevent gets treated special, and even though it's not a real logging category, bitcoind prints an error and ignores the option.

    "remove the libevent debug log category" might mean:

    a) remove it internally in bitcoin core's code - This PR does that and users probably don't care whether or not this happens. b) the option does nothing - Already true on master, not that interesting except for maybe telling users that cared to turn on debug=http instead c) gets treated like every other nonexisting logging category and results in an error and refusal to start - Might happen at some point in the future and users should be warned.

    My understanding is that what is meant in the release note and this PR by "removed" is c) but it might be clearer if written more like the suggestion above


    ryanofsky commented at 7:05 PM on June 29, 2026:

    re: #35597 (review)

    still mentions the logging being deprecated and that it will be removed

    Yes this is still keeping compatibility and not removing the option. Just no longer listing a category that doesn't produce any output. I did update the release notes though to hopefully be clearer.

  5. in test/functional/rpc_misc.py:128 in d38170a4eb
     127 | -            assert_equal(value, category != "libevent")
     128 | +        all_result = node.logging(include=['all'])
     129 | +        assert_equal(True, all(value is True for category, value in all_result.items()))
     130 | +        assert_equal(True, 'libevent' not in all_result)
     131 | +        assert_equal(all_result, node.logging())
     132 |          with self.nodes[0].assert_debug_log(["The logging category `libevent` is deprecated"]):
    


    l0rinc commented at 5:40 PM on June 24, 2026:

    Could extract the expected warning into a local variable so the include/exclude cases stay in sync, especially if the warning wording changes.


    ryanofsky commented at 7:27 PM on June 29, 2026:

    re: #35597 (review)

    Could extract the expected warning into a local variable so the include/exclude cases stay in sync, especially if the warning wording changes.

    Makes sense, added variable

  6. in test/functional/rpc_misc.py:126 in d38170a4eb
     125 | -        for category, value in node.logging().items():
     126 | -            # Everything True except one...
     127 | -            assert_equal(value, category != "libevent")
     128 | +        all_result = node.logging(include=['all'])
     129 | +        assert_equal(True, all(value is True for category, value in all_result.items()))
     130 | +        assert_equal(True, 'libevent' not in all_result)
    


    l0rinc commented at 5:42 PM on June 24, 2026:

    The all-true result and absent libevent key are boolean predicates, so plain assertions should be enough. This also avoids the unused category loop variable:

            assert all(value is True for value in all_result.values())
            assert 'libevent' not in all_result
    

    ryanofsky commented at 7:34 PM on June 29, 2026:

    re: #35597 (review)

    The all-true result and absent libevent key are boolean predicates, so plain assertions should be enough. This also avoids the unused category loop variable:

    Thanks for the suggestion. I think it's better to use items() instead of .values() here and keep both variables so it's more obvious this returns a category -> bool mapping. Also I think it's better to use the test framework's checks for consistency and since failing language asserts would look more like test bugs than test failures. So I didn't use these suggestions but I did rename value -> enabled

  7. in src/logging.cpp:236 in d38170a4eb
     231 | @@ -243,6 +232,10 @@ std::optional<BCLog::LogFlags> BCLog::Logger::GetLogCategory(std::string_view st
     232 |      if (it != LOG_CATEGORIES_BY_STR.end()) {
     233 |          return it->second;
     234 |      }
     235 | +    if (str == "libevent") {
     236 | +       LogWarning("The logging category `%s` is deprecated, can not be enabled, and will be removed in a future version", str);
    


    davidgumberg commented at 5:45 PM on June 24, 2026:

    text bikeshed, I think what this means will not be obvious to a user but I'm fine with as-is:

           LogWarning("The logging category `%s` is deprecated, does nothing, and will result in an error in a future version", str);
    

    ryanofsky commented at 7:01 PM on June 29, 2026:

    re: #35597 (review)

    text bikeshed, I think what this means will not be obvious to a user but I'm fine with as-is:

    Thanks! Agree that's much better

  8. in src/logging.cpp:237 in d38170a4eb outdated
     231 | @@ -243,6 +232,10 @@ std::optional<BCLog::LogFlags> BCLog::Logger::GetLogCategory(std::string_view st
     232 |      if (it != LOG_CATEGORIES_BY_STR.end()) {
     233 |          return it->second;
     234 |      }
     235 | +    if (str == "libevent") {
     236 | +       LogWarning("The logging category `%s` is deprecated, can not be enabled, and will be removed in a future version", str);
     237 | +       return BCLog::NONE;
    


    l0rinc commented at 5:51 PM on June 24, 2026:

    Since libevent resolves to BCLog::NONE to preserve compatibility without enabling a real category, SetCategoryLogLevel() can avoid storing a category-specific level for it.

    diff --git a/src/logging.cpp b/src/logging.cpp
    index 03ef1dd603..a9585a72d4 100644
    --- a/src/logging.cpp
    +++ b/src/logging.cpp
    @@ -609,6 +609,7 @@ bool BCLog::Logger::SetCategoryLogLevel(std::string_view category_str, std::stri
     
         const auto level = GetLogLevel(level_str);
         if (!level.has_value() || level.value() > MAX_USER_SETABLE_SEVERITY_LEVEL) return false;
    +    if (*flag == BCLog::NONE) return true;
     
         STDLOCK(m_cs);
         m_category_log_levels[*flag] = level.value();
    diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp
    index 5595fe16de..7f0aac56c7 100644
    --- a/src/test/logging_tests.cpp
    +++ b/src/test/logging_tests.cpp
    @@ -244,6 +244,13 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
             BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Trace);
         }
     
    +    // Ignore removed libevent category-specific log level
    +    {
    +        ResetLogger();
    +        BOOST_CHECK(LogInstance().SetCategoryLogLevel(/*category_str=*/"libevent", /*level_str=*/"trace"));
    +        BOOST_CHECK(LogInstance().CategoryLevels().empty());
    +    }
    +
         // Set both global log level and category-specific log level
         {
             ResetLogger();
    

    janb84 commented at 9:04 AM on June 25, 2026:

    NIT: This change introduces a logging side-effect to a (almost) pure table lookup.

    The diff below moves the warning out to the action sites, keeps GetLogCategory pure and removes the need to return BCLog::NONE;

    In my change GetLogCategory stays a plain table lookup returning nullopt for unknown strings, and each of EnableCategory / DisableCategory / SetCategoryLogLevel falls through to WarnIfDeprecatedCategory(str) on a miss.

    Not a blocker, this is temporary code after all but still.

    diff --git a/src/logging.cpp b/src/logging.cpp
    index 701e063dce..c45dd74ad9 100644
    --- a/src/logging.cpp
    +++ b/src/logging.cpp
    @@ -125,6 +125,15 @@ void BCLog::Logger::DisableLogging()
         StartLogging();
     }
     
    +static bool WarnIfDeprecatedCategory(std::string_view str)
    +{
    +    if (str == "libevent") {
    +        LogWarning("The logging category `%s` is deprecated, can not be enabled, and will be removed in a future version", str);
    +        return true;
    +    }
    +    return false;
    +}
    +
     void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
     {
         m_categories |= flag;
    @@ -136,7 +145,7 @@ bool BCLog::Logger::EnableCategory(std::string_view str)
             EnableCategory(*flag);
             return true;
         }
    -    return false;
    +    return WarnIfDeprecatedCategory(str);
     }
     
     void BCLog::Logger::DisableCategory(BCLog::LogFlags flag)
    @@ -150,7 +159,7 @@ bool BCLog::Logger::DisableCategory(std::string_view str)
             DisableCategory(*flag);
             return true;
         }
    -    return false;
    +    return WarnIfDeprecatedCategory(str);
     }
     
     bool BCLog::Logger::WillLogCategory(BCLog::LogFlags category) const
    @@ -232,10 +241,6 @@ std::optional<BCLog::LogFlags> BCLog::Logger::GetLogCategory(std::string_view st
         if (it != LOG_CATEGORIES_BY_STR.end()) {
             return it->second;
         }
    -    if (str == "libevent") {
    -       LogWarning("The logging category `%s` is deprecated, can not be enabled, and will be removed in a future version", str);
    -       return BCLog::NONE;
    -    }
         return std::nullopt;
     }
     
    @@ -605,7 +610,7 @@ bool BCLog::Logger::SetLogLevel(std::string_view level_str)
     bool BCLog::Logger::SetCategoryLogLevel(std::string_view category_str, std::string_view level_str)
     {
         const auto flag{GetLogCategory(category_str)};
    -    if (!flag) return false;
    +    if (!flag) return WarnIfDeprecatedCategory(category_str);
     
         const auto level = GetLogLevel(level_str);
         if (!level.has_value() || level.value() > MAX_USER_SETABLE_SEVERITY_LEVEL) return false;
    

    ryanofsky commented at 7:50 PM on June 29, 2026:

    re: #35597 (review)

    NIT: This change introduces a logging side-effect to a (almost) pure table lookup.

    I think the current change is more appropriate than the suggested code (and previous code), because the category lookup is what is failing, so it makes sense to handle the lookup failure one place instead of every place the lookup is performed.

    I do also agree with you that it would be nice if the lookup function was pure and didn't log a warning. This could be implemented pretty simply by having a GetLogCategory function that's pure and a ParseLogCategory function that calls GetLogCategory and is impure. But at the moment no callers need the pure function and all callers need to impure function, so I think it makes sense to have one simple function until something more complicated is needed.


    ryanofsky commented at 12:38 AM on June 30, 2026:

    re: #35597 (review)

    Since libevent resolves to BCLog::NONE to preserve compatibility without enabling a real category, SetCategoryLogLevel() can avoid storing a category-specific level for it.

    Thanks, it does seem a little better not to store this even though it won't be used, so I applied the patch.

    This ambiguity would not exist if representation of log levels was a simple (category -> level) mapping instead of the current (category -> level or global default level + enabled or disabled) mapping.

  9. l0rinc approved
  10. ryanofsky force-pushed on Jun 30, 2026
  11. ryanofsky commented at 1:04 AM on June 30, 2026: contributor

    Thanks for the reviews!

    <!-- begin push-2 -->

    Updated d38170a4eb10aa6df622582caa42c354cc09c285 -> 3765b428d1950a4ffbe85f9fb66ff1a3a73d0167 (pr/logevent.1 -> pr/logevent.2, compare)<!-- end --> with suggested changes.

  12. l0rinc commented at 1:53 AM on June 30, 2026: contributor

    code review ACK 3765b428d1950a4ffbe85f9fb66ff1a3a73d0167

  13. DrahtBot requested review from davidgumberg on Jun 30, 2026
  14. pinheadmz approved
  15. pinheadmz commented at 3:26 PM on June 30, 2026: member

    ACK 3765b428d1950a4ffbe85f9fb66ff1a3a73d0167

    Built and tested on arm64/macos. Played with config args and rpc logging, behavior is mostly unchanged. Removes the code around "deprecated" logging categories and redefines libevent as "known" but not supported, so it doesn't show up in any lists but also doesn't raise an error if a consumer of the API hasn't adjusted for #35182 yet. Only downside is a hardcoded if "libevent" but I agree its cleaner than what we had before.

    <details><summary>Show Signature</summary>

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA256
    
    ACK 3765b428d1950a4ffbe85f9fb66ff1a3a73d0167
    -----BEGIN PGP SIGNATURE-----
    
    iQJPBAEBCAA5FiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmpD32IbFIAAAAAABAAO
    bWFudTIsMi41KzEuMTIsMCwzAAoJEOfimEtiick674YQAKg+MQ6usxyIVWqqIMrU
    oWMql9QIm49yqeg+tiLHaEUZ2d1TN5OgWp4jouDctx+ugfDpl1InnAp7yzGA+LTx
    RFjzVC2/NIUIjNiZ+7FKQaA205MLT1ygmWQyG0OWSeqMUBwKMv0VMWNkQdt91ZFG
    BTGBtgSaHldXD2tZKnx0pBg2aDE0GY4mUh6VnqfxnatJ0hqTAcW+lvtNzt46HKJZ
    /1yl8f8VLj9Mk2MNGi5WZhqIG2GoaIpb3YzleSa2h+bhvVUNzIWVGrrQ6+n9EFTx
    mXIN2eSSpXYIAVDH86P3ClDIMJtIBz0mXxPCj91ioIBtOsYM0gCIcF70AlqzGpUq
    JfRK+qAnIupg0xZluN135K6+1LI7hPLkn7LaXiGH/cz1xN5qeCcCoMexFSxeChVt
    5slLzIiVy68U2uu4MVsG7Hi+V2wsSiQPEOhrykLtoHf4Ri0MtSCBOBCREDn0n7dE
    +piFRDGi4W/g7n8BaxlPamz4A0AwgB8QgoZ5m++h1YVuyZ3N+bIpamVrbEOrLOwL
    c+6jpqIcGnhWAyxQv5Ak8Ma0iEicnmXnoXA9+mWN/9vg9vjF9hMDYHnclLpIutDr
    N/5ghsUzI6LKOmZafmISVM+qi/iZEBs/kWAujbqT252avEDvu1mH2MaaoGb9oDr5
    0SbUTIBTAiIZw1I7UkeGLjfY
    =Pt2t
    -----END PGP SIGNATURE-----
    

    pinheadmz's public key is on openpgp.org

    </details>

  16. sedited approved
  17. sedited commented at 3:36 PM on June 30, 2026: contributor

    ACK 3765b428d1950a4ffbe85f9fb66ff1a3a73d0167

  18. sedited merged this on Jun 30, 2026
  19. sedited closed this on Jun 30, 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-07-09 06:47 UTC