logging: Ensure -debug=0/none behaves consistently with -nodebug #31767

pull danielabrozzoni wants to merge 3 commits into bitcoin:master from danielabrozzoni:debug_flag_consistency changing 3 files +27 −7
  1. danielabrozzoni commented at 5:04 pm on January 30, 2025: contributor

    Previously, -nodebug cleared all prior -debug configurations in the command line while allowing subsequent debug options to be applied. However, -debug=0 and -debug=none completely disabled debugging, even for categories specified afterward.

    This commit ensures consistency by making -debug=0 and -debug=none behave like -nodebug: they now clear previously set debug configurations but do not disable debugging for categories specified later.

    See #30529 (review)

  2. DrahtBot commented at 5:04 pm on January 30, 2025: contributor

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

    Code Coverage & Benchmarks

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hodlinator, ryanofsky, maflcko

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #30529 (Fix -norpcwhitelist, -norpcallowip, and similar corner case behavior 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.

  3. DrahtBot added the label RPC/REST/ZMQ on Jan 30, 2025
  4. danielabrozzoni force-pushed on Jan 30, 2025
  5. danielabrozzoni force-pushed on Jan 30, 2025
  6. in doc/release-notes-31767.md:1 in 55c752a6d8 outdated
    0@@ -0,0 +1,3 @@
    1+RPC
    


    maflcko commented at 1:28 pm on February 4, 2025:
    What is the connection to RPC? I was under the impression that -debug is a setting related to logging.

    danielabrozzoni commented at 2:58 pm on February 4, 2025:
    You’re right, thanks! Updated with “Logging” as it feels more appropriate to me too

    luke-jr commented at 4:07 am on February 5, 2025:
    PR title and commit message too, please
  7. danielabrozzoni force-pushed on Feb 4, 2025
  8. DrahtBot added the label CI failed on Feb 4, 2025
  9. DrahtBot removed the label CI failed on Feb 4, 2025
  10. danielabrozzoni renamed this:
    rpc: Ensure -debug=0/none behaves consistently with -nodebug
    logging: Ensure -debug=0/none behaves consistently with -nodebug
    on Feb 5, 2025
  11. danielabrozzoni force-pushed on Feb 5, 2025
  12. DrahtBot added the label CI failed on Feb 5, 2025
  13. DrahtBot removed the label CI failed on Feb 5, 2025
  14. maflcko removed the label RPC/REST/ZMQ on Feb 5, 2025
  15. in src/init/common.cpp:93 in 1f4aff75c3 outdated
    93+        auto last_negated = categories.rbegin();
    94+        for (; last_negated != categories.rend(); ++last_negated) {
    95+            if (*last_negated == "0" || *last_negated == "none") {
    96+                break;
    97+            }
    98+        }
    


    hodlinator commented at 8:17 pm on February 6, 2025:

    nit: I tried to replicate what ChatGPT suggested to ryanofsky, but std::views wouldn’t compile (didn’t look into modifying my setup). Was able to combine it with your version though into:

    0        auto last_negated = std::find_if(categories.rbegin(), categories.rend(),
    1            [](const std::string& cat) { return cat == "0" || cat == "none"; });
    

    danielabrozzoni commented at 4:58 pm on February 10, 2025:
    This is way nicer! Updated, thanks
  16. in src/init/common.cpp:93 in 1f4aff75c3 outdated
     99+
    100+        auto range_to_process = (last_negated == categories.rend()) ? categories : std::ranges::subrange(last_negated.base(), categories.end());
    101+
    102+        for (const auto& cat : range_to_process) {
    103+            if (!LogInstance().EnableCategory(cat)) {
    104+                return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)};
    


    hodlinator commented at 8:19 pm on February 6, 2025:

    mega-nit: I find this marginally nicer, but still not great:

    0        for (auto it = last_negated == categories.rend() ? categories.begin() : last_negated.base();
    1            it != categories.end(); ++it) {
    2            if (!LogInstance().EnableCategory(*it)) {
    3                return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debug", *it)};
    

    danielabrozzoni commented at 4:59 pm on February 10, 2025:
    I find this a bit harder to read, so I’ll keep it as it is.
  17. in test/functional/feature_logging.py:106 in 1f4aff75c3 outdated
     98@@ -99,6 +99,18 @@ def run_test(self):
     99             match=ErrorMatch.PARTIAL_REGEX,
    100         )
    101 
    102+        self.log.info("Test that -nodebug,-debug=0,-debug=none clear previously specified debug options")
    103+        disable_debug_options = [
    104+            '-debug=0',
    105+            '-debug=none',
    106+            '-nodebug'
    


    hodlinator commented at 8:21 pm on February 6, 2025:
    nit: I tested breaking out an initial commit which only adds the test for -nodebug to prove existing behavior, before the commit performing the C++ change and adding 0 + none tests (it passed). You might want to rewrite the commit history to do that as well, but I’m okay with the current approach.
  18. in test/functional/feature_logging.py:112 in 1f4aff75c3 outdated
    107+        ]
    108+
    109+        for debug_opt in disable_debug_options:
    110+            self.restart_node(0, ['-debug=http', debug_opt, '-debug=rpc'])
    111+            logging = self.nodes[0].logging()
    112+            assert logging['rpc']
    


    hodlinator commented at 8:23 pm on February 6, 2025:

    nit: Could add invalid abc category prior to disabling, and verify that multiple categories after the disabling work.

    0            self.restart_node(0, ['-debug=http', '-debug=abc', debug_opt, '-debug=rpc', '-debug=net'])
    1            logging = self.nodes[0].logging()
    2            assert logging['rpc']
    3            assert logging['net']
    

    hodlinator commented at 10:21 pm on February 10, 2025:
  19. hodlinator approved
  20. hodlinator commented at 8:50 pm on February 6, 2025: contributor

    ACK 1f4aff75c308226d58a45460982f75287e15cb81

    Concept

    Having -debug=0 and -debug=none perform the same effect as -nodebug in discarding all preceding categories makes more sense, instead of disabling all categories including the ones following them.

    Testing

    As well as running the new test as-is, I also verified stated behavior of -nodebug prior to the C++ change by modifying included test.

    Suggestions

    Only found nits, the last_negated calculation in particular feels unnecessarily verbose & mutation heavy.

  21. danielabrozzoni force-pushed on Feb 10, 2025
  22. danielabrozzoni commented at 5:11 pm on February 10, 2025: contributor

    Thank you for the reviews! In my last push:

    • I removed every occurences of “rpc” (sorry I didn’t catch them the first time!)
    • I’ve renamed a couple of variables, added a comment, and addressed @hodlinator’s nits, to improve clarity
  23. in src/init/common.cpp:94 in bb8309723c outdated
     96+        for (; last_negated != categories.rend(); ++last_negated) {
     97+            if (*last_negated == "0" || *last_negated == "none") {
     98+                break;
     99+            }
    100+        }
    101+
    


    hodlinator commented at 10:32 pm on February 10, 2025:

    Seems like you forgot to remove this? (last_negated should theoretically be able to be marked const, but makes line go over 80 chars).


    danielabrozzoni commented at 11:04 am on February 11, 2025:
    Of course! Thank you, updated, and made last_negated and categories_to_process const
  24. test: `-nodebug` clears previously set debug options d39d521d86
  25. logging: Ensure -debug=0/none behaves consistently with -nodebug
    Previously, -nodebug cleared all prior -debug configurations in the
    command line while allowing subsequent debug options to be applied.
    However, -debug=0 and -debug=none completely disabled debugging,
    even for categories specified afterward.
    
    This commit ensures consistency by making -debug=0 and -debug=none
    behave like -nodebug: they now clear previously set debug configurations
    but do not disable debugging for categories specified later.
    
    Co-Authored-By: Ryan Ofsky <ryan@ofsky.org>
    a8fedb36a7
  26. test: `-debug=0` and `-debug=none` behave similarly to `-nodebug` 7afeaa2469
  27. danielabrozzoni force-pushed on Feb 11, 2025
  28. hodlinator approved
  29. hodlinator commented at 1:19 pm on February 11, 2025: contributor

    re-ACK 7afeaa24693039730c9ae00c325c2b9d0e2deda1

    Changes since previous ACK:

    • Broke out initial commit which tests prior behavior (with minor improvements).
    • Terser test for last occurrence of negated arg suggested by self.
  30. ryanofsky approved
  31. ryanofsky commented at 3:10 pm on February 12, 2025: contributor
    Code review ACK 7afeaa24693039730c9ae00c325c2b9d0e2deda1. Nicely implemented change with test and release notes, and I like how the test is implemented as the first commit.
  32. in src/init/common.cpp:82 in a8fedb36a7 outdated
    79@@ -80,15 +80,17 @@ util::Result<void> SetLoggingLevel(const ArgsManager& args)
    80 util::Result<void> SetLoggingCategories(const ArgsManager& args)
    81 {
    82     if (args.IsArgSet("-debug")) {
    


    maflcko commented at 11:13 am on February 13, 2025:

    Nit in a8fedb36a71ac193fc158284b14d4eb474e5ab62: Why is this needed? It seems like a no-op:

    • If the list of debug args is empty, the code below can handle it. In fact, it must handle the case anyway. For example, if someone passes just -nodebug, IsArgSet will be true, but GetArgs will be empty.
    • If the list of debug args is not empty, it is just a redundant check?

    So my recommendation would be to remove it. If you want, you can keep the {} for the scope.


    ryanofsky commented at 12:46 pm on February 13, 2025:

    re: #31767 (review)

    Nit in a8fedb3: Why is this needed? It seems like a no-op:

    Right it is is a no-op, see #30529 which makes the change you suggested and removes many other misuses of IsArgSet


    maflcko commented at 1:19 pm on February 13, 2025:
    Thx for confirming. It would be nice to remove it here, so that it doesn’t have to be touched (and reviewed) again in another pull request. But it was just a nit and anything is fine.

    ryanofsky commented at 1:40 pm on February 13, 2025:

    Thx for confirming. It would be nice to remove it here, so that it doesn’t have to be touched (and reviewed) again in another pull request.

    Yep, #30529 does have 2 acks though so getting close

  33. in src/init/common.cpp:85 in a8fedb36a7 outdated
    87-            [](std::string cat){return cat == "0" || cat == "none";})) {
    88-            for (const auto& cat : categories) {
    89-                if (!LogInstance().EnableCategory(cat)) {
    90-                    return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)};
    91-                }
    92+        // Special-case: Disregard any debugging categories appearing before -debug=0/none
    


    maflcko commented at 11:21 am on February 13, 2025:
    Nit in https://github.com/bitcoin/bitcoin/commit/a8fedb36a71ac193fc158284b14d4eb474e5ab62: Would be nice to explain why this is done: Something like: // GetArgs disregards any debugging categories appearing before -nodebug, so do the same for -debug=0/none

    ryanofsky commented at 1:08 pm on February 13, 2025:

    Nit in a8fedb3: Would be nice to explain why this is done: Something like: // GetArgs disregards any debugging categories appearing before -nodebug, so do the same for -debug=0/none

    Could be good to add a reason for this, but the suggested reason is pretty obscure one. I think the general reason for doing this is that later arguments are supposed to take precedence over earlier ones, so when -debug=none is followed by -debug=something, -debug=something should take precedence, and vice versa.

  34. maflcko approved
  35. maflcko commented at 11:22 am on February 13, 2025: member

    left two nits

    review ACK 7afeaa24693039730c9ae00c325c2b9d0e2deda1 👡

    Signature:

    0untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    1RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    2trusted comment: review ACK 7afeaa24693039730c9ae00c325c2b9d0e2deda1 👡
    3ArIz38cfPYwJHMq9d1QKT9t9zk+QWETW8C/1e1B83bsin8cm2QVQRHActkHAgZSX49gcc2TtDyMFdPVuDcWZDw==
    
  36. ryanofsky merged this on Feb 13, 2025
  37. ryanofsky closed this on Feb 13, 2025


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: 2025-02-23 09:12 UTC

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