diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -955,9 +955,8 @@ 0) + ". " + "If is not supplied or if = 1, " - "output all debugging information." - " can be: " + - ListLogCategories() + ".", + "output all debugging information. can be: " + + LogInstance().LogCategoriesString() + ".", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg( "-debugexclude=", diff --git a/src/logging.h b/src/logging.h --- a/src/logging.h +++ b/src/logging.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -25,7 +26,7 @@ extern bool fLogIPs; extern const char *const DEFAULT_DEBUGLOGFILE; -struct CLogCategoryActive { +struct LogCategory { std::string category; bool active; }; @@ -142,6 +143,14 @@ /** Return true if log accepts specified category */ bool WillLogCategory(LogFlags category) const; + /** Returns a vector of the log categories */ + std::vector LogCategoriesList(); + /** Returns a string with the log categories */ + std::string LogCategoriesString() { + return Join(LogCategoriesList(), ", ", + [&](const LogCategory &i) { return i.category; }); + }; + /** Default for whether ShrinkDebugFile should be run */ bool DefaultShrinkDebugFile() const; }; @@ -155,12 +164,6 @@ return LogInstance().WillLogCategory(category); } -/** Returns a string with the log categories. */ -std::string ListLogCategories(); - -/** Returns a vector of the active log categories. */ -std::vector ListActiveLogCategories(); - /** Return true if str parses as a log category and set the flag */ bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str); diff --git a/src/logging.cpp b/src/logging.cpp --- a/src/logging.cpp +++ b/src/logging.cpp @@ -139,32 +139,15 @@ return false; } -std::string ListLogCategories() { - std::string ret; - int outcount = 0; - for (const CLogCategoryDesc &category_desc : LogCategories) { - // Omit the special cases. - if (category_desc.flag != BCLog::NONE && - category_desc.flag != BCLog::ALL) { - if (outcount != 0) { - ret += ", "; - } - ret += category_desc.category; - outcount++; - } - } - return ret; -} - -std::vector ListActiveLogCategories() { - std::vector ret; +std::vector BCLog::Logger::LogCategoriesList() { + std::vector ret; for (const CLogCategoryDesc &category_desc : LogCategories) { // Omit the special cases. if (category_desc.flag != BCLog::NONE && category_desc.flag != BCLog::ALL) { - CLogCategoryActive catActive; + LogCategory catActive; catActive.category = category_desc.category; - catActive.active = LogAcceptCategory(category_desc.flag); + catActive.active = WillLogCategory(category_desc.flag); ret.push_back(catActive); } } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -641,7 +641,7 @@ "If an item is both included and excluded, it will thus end up being " "excluded.\n" "The valid logging categories are: " + - ListLogCategories() + + LogInstance().LogCategoriesString() + "\n" "In addition, the following are available as category names with " "special meanings:\n" @@ -713,8 +713,7 @@ } UniValue result(UniValue::VOBJ); - std::vector vLogCatActive = ListActiveLogCategories(); - for (const auto &logCatActive : vLogCatActive) { + for (const auto &logCatActive : LogInstance().LogCategoriesList()) { result.pushKV(logCatActive.category, logCatActive.active); }