mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
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>
This commit is contained in:
parent
d39d521d86
commit
a8fedb36a7
2 changed files with 12 additions and 7 deletions
3
doc/release-notes-31767.md
Normal file
3
doc/release-notes-31767.md
Normal file
|
@ -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.
|
|
@ -80,15 +80,17 @@ util::Result<void> SetLoggingLevel(const ArgsManager& args)
|
||||||
util::Result<void> SetLoggingCategories(const ArgsManager& args)
|
util::Result<void> SetLoggingCategories(const ArgsManager& args)
|
||||||
{
|
{
|
||||||
if (args.IsArgSet("-debug")) {
|
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");
|
const std::vector<std::string> categories = args.GetArgs("-debug");
|
||||||
|
|
||||||
if (std::none_of(categories.begin(), categories.end(),
|
// Special-case: Disregard any debugging categories appearing before -debug=0/none
|
||||||
[](std::string cat){return cat == "0" || cat == "none";})) {
|
const auto last_negated = std::find_if(categories.rbegin(), categories.rend(),
|
||||||
for (const auto& cat : categories) {
|
[](const std::string& cat) { return cat == "0" || cat == "none"; });
|
||||||
if (!LogInstance().EnableCategory(cat)) {
|
|
||||||
return util::Error{strprintf(_("Unsupported logging category %s=%s."), "-debug", cat)};
|
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)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue