diff --git a/doc/release-notes-31767.md b/doc/release-notes-31767.md new file mode 100644 index 00000000000..f2247cfbeb0 --- /dev/null +++ b/doc/release-notes-31767.md @@ -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. diff --git a/src/init/common.cpp b/src/init/common.cpp index 70c4230cfdb..bc0a2f65080 100644 --- a/src/init/common.cpp +++ b/src/init/common.cpp @@ -80,15 +80,17 @@ util::Result SetLoggingLevel(const ArgsManager& args) util::Result SetLoggingCategories(const ArgsManager& args) { if (args.IsArgSet("-debug")) { - // Special-case: if -debug=0/-nodebug is set, turn off debugging messages const std::vector 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)}; } } }