Skip to content

Commit

Permalink
Merge bitcoin#31767: logging: Ensure -debug=0/none behaves consistent…
Browse files Browse the repository at this point in the history
…ly with -nodebug

7afeaa2 test: `-debug=0` and `-debug=none` behave similarly to `-nodebug` (Daniela Brozzoni)
a8fedb3 logging: Ensure -debug=0/none behaves consistently with -nodebug (Daniela Brozzoni)
d39d521 test: `-nodebug` clears previously set debug options (Daniela Brozzoni)

Pull request description:

  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 bitcoin#30529 (comment)

ACKs for top commit:
  hodlinator:
    re-ACK 7afeaa2
  ryanofsky:
    Code review ACK 7afeaa2. Nicely implemented change with test and release notes, and I like how the test is implemented as the first commit.
  maflcko:
    review ACK 7afeaa2 👡

Tree-SHA512: c69b17ff10da6c88636bd01918366dd408832e70f2d0a7b951e9619089e89c39282db70398ba2542d3aa69a2fe6b6a0a01638b3225aff79d234d84d3067f2caa
  • Loading branch information
ryanofsky committed Feb 13, 2025
2 parents a5b0a44 + 7afeaa2 commit 251ea73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions doc/release-notes-31767.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Logging
---
Passing -debug=0 or -debug=none now behaves like -nodebug: previously set debug categories will be cleared, but subsequent -debug options will still be applied.
16 changes: 9 additions & 7 deletions src/init/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ util::Result<void> SetLoggingLevel(const ArgsManager& args)
util::Result<void> SetLoggingCategories(const ArgsManager& args)
{
if (args.IsArgSet("-debug")) {
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
const std::vector<std::string> categories = args.GetArgs("-debug");

if (std::none_of(categories.begin(), categories.end(),
[](std::string cat){return cat == "0" || cat == "none";})) {
for (const auto& cat : categories) {
if (!LogInstance().EnableCategory(cat)) {
return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)};
}
// Special-case: Disregard any debugging categories appearing before -debug=0/none
const auto last_negated = std::find_if(categories.rbegin(), categories.rend(),
[](const std::string& cat) { return cat == "0" || cat == "none"; });

const auto categories_to_process = (last_negated == categories.rend()) ? categories : std::ranges::subrange(last_negated.base(), categories.end());

for (const auto& cat : categories_to_process) {
if (!LogInstance().EnableCategory(cat)) {
return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)};
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/functional/feature_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ def run_test(self):
match=ErrorMatch.PARTIAL_REGEX,
)

self.log.info("Test that -nodebug,-debug=0,-debug=none clear previously specified debug options")
disable_debug_options = [
'-debug=0',
'-debug=none',
'-nodebug'
]

for disable_debug_opt in disable_debug_options:
# Every category before disable_debug_opt will be ignored, including the invalid 'abc'
self.restart_node(0, ['-debug=http', '-debug=abc', disable_debug_opt, '-debug=rpc', '-debug=net'])
logging = self.nodes[0].logging()
assert not logging['http']
assert 'abc' not in logging
assert logging['rpc']
assert logging['net']

if __name__ == '__main__':
LoggingTest(__file__).main()

0 comments on commit 251ea73

Please sign in to comment.