Skip to content

Commit 251ea73

Browse files
committed
Merge bitcoin#31767: logging: Ensure -debug=0/none behaves consistently 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
2 parents a5b0a44 + 7afeaa2 commit 251ea73

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

doc/release-notes-31767.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Logging
2+
---
3+
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.

src/init/common.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,17 @@ util::Result<void> SetLoggingLevel(const ArgsManager& args)
8080
util::Result<void> SetLoggingCategories(const ArgsManager& args)
8181
{
8282
if (args.IsArgSet("-debug")) {
83-
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
8483
const std::vector<std::string> categories = args.GetArgs("-debug");
8584

86-
if (std::none_of(categories.begin(), categories.end(),
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-
}
85+
// Special-case: Disregard any debugging categories appearing before -debug=0/none
86+
const auto last_negated = std::find_if(categories.rbegin(), categories.rend(),
87+
[](const std::string& cat) { return cat == "0" || cat == "none"; });
88+
89+
const auto categories_to_process = (last_negated == categories.rend()) ? categories : std::ranges::subrange(last_negated.base(), categories.end());
90+
91+
for (const auto& cat : categories_to_process) {
92+
if (!LogInstance().EnableCategory(cat)) {
93+
return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)};
9294
}
9395
}
9496
}

test/functional/feature_logging.py

+15
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ def run_test(self):
9999
match=ErrorMatch.PARTIAL_REGEX,
100100
)
101101

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'
107+
]
108+
109+
for disable_debug_opt in disable_debug_options:
110+
# Every category before disable_debug_opt will be ignored, including the invalid 'abc'
111+
self.restart_node(0, ['-debug=http', '-debug=abc', disable_debug_opt, '-debug=rpc', '-debug=net'])
112+
logging = self.nodes[0].logging()
113+
assert not logging['http']
114+
assert 'abc' not in logging
115+
assert logging['rpc']
116+
assert logging['net']
102117

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

0 commit comments

Comments
 (0)