From c034ff0c2606142ba3e8894bc74f693b87374e5c Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 28 Sep 2023 15:47:45 +0300 Subject: [PATCH] fix: `debug` rpc should return a list of active debug categories, not all of them (#5585) ## Issue being fixed or feature implemented This restores previous behaviour which was changed/broken here https://github.com/dashpay/dash/commit/e554d3a02e58a298c9f2b10a8bee443cbfc8ed54#diff-0ba691cbdd97c095286e9373ed8d5be87d559234440487956326965e16cbb421R75 ## What was done? Fix `debug` rpc results ## How Has This Been Tested? Run rpc, check results ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ --------- Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> --- src/logging.cpp | 6 ++++-- src/logging.h | 6 +++--- src/rpc/misc.cpp | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index 7b4a5956c7..e64d76c988 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -197,7 +197,7 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str) return false; } -std::vector BCLog::Logger::LogCategoriesList() const +std::vector BCLog::Logger::LogCategoriesList(bool enabled_only) const { std::vector ret; for (const CLogCategoryDesc& category_desc : LogCategories) { @@ -206,7 +206,9 @@ std::vector BCLog::Logger::LogCategoriesList() const LogCategory catActive; catActive.category = category_desc.category; catActive.active = WillLogCategory(category_desc.flag); - ret.push_back(catActive); + if (!enabled_only || catActive.active) { + ret.push_back(catActive); + } } } return ret; diff --git a/src/logging.h b/src/logging.h index 7810e318ce..af3423edf8 100644 --- a/src/logging.h +++ b/src/logging.h @@ -158,11 +158,11 @@ namespace BCLog { bool WillLogCategory(LogFlags category) const; /** Returns a vector of the log categories */ - std::vector LogCategoriesList() const; + std::vector LogCategoriesList(bool enabled_only = false) const; /** Returns a string with the log categories */ - std::string LogCategoriesString() const + std::string LogCategoriesString(bool enabled_only = false) const { - return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; }); + return Join(LogCategoriesList(enabled_only), ", ", [&](const LogCategory& i) { return i.category; }); }; bool DefaultShrinkDebugFile() const; diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index edf09cfb13..c4cf607f61 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -72,7 +72,7 @@ static UniValue debug(const JSONRPCRequest& request) } } - return "Debug mode: " + LogInstance().LogCategoriesString(); + return "Debug mode: " + LogInstance().LogCategoriesString(/*enabled_only=*/true); } static UniValue mnsync(const JSONRPCRequest& request)