mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
Merge bitcoin/bitcoin#31767: logging: Ensure -debug=0/none behaves consistently with -nodebug
7afeaa2469test: `-debug=0` and `-debug=none` behave similarly to `-nodebug` (Daniela Brozzoni)a8fedb36a7logging: Ensure -debug=0/none behaves consistently with -nodebug (Daniela Brozzoni)d39d521d86test: `-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 https://github.com/bitcoin/bitcoin/pull/30529#discussion_r1930956563 ACKs for top commit: hodlinator: re-ACK7afeaa2469ryanofsky: Code review ACK7afeaa2469. Nicely implemented change with test and release notes, and I like how the test is implemented as the first commit. maflcko: review ACK7afeaa2469👡 Tree-SHA512: c69b17ff10da6c88636bd01918366dd408832e70f2d0a7b951e9619089e89c39282db70398ba2542d3aa69a2fe6b6a0a01638b3225aff79d234d84d3067f2caa
This commit is contained in:
@@ -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)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user