Skip to content

Commit a8fedb3

Browse files
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>
1 parent d39d521 commit a8fedb3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

doc/release-notes-31767.md

Lines changed: 3 additions & 0 deletions
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

Lines changed: 9 additions & 7 deletions
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
}

0 commit comments

Comments
 (0)