In commit "logging: remove unused BCLog::UTIL" (b0344c219a641b759fb0cc4f53afebe675b8ca27)
I think it would make code more straightforward if we could drop these special cases here and avoid having discrepancies between LOG_CATEGORIES_BY_FLAG and LOG_CATEGORIES_BY_STR maps.
There are already special cases in existing GetLogCategory and LogCategoriesList functions so I think it would make more sense to put new special cases there and not introduce them in a third place. Would suggest:
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -142,7 +142,6 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const
}
static const std::map<std::string, BCLog::LogFlags> LOG_CATEGORIES_BY_STR{
- {"0", BCLog::NONE},
{"", BCLog::NONE},
{"net", BCLog::NET},
{"tor", BCLog::TOR},
@@ -175,7 +174,6 @@ static const std::map<std::string, BCLog::LogFlags> LOG_CATEGORIES_BY_STR{
{"txreconciliation", BCLog::TXRECONCILIATION},
{"scan", BCLog::SCAN},
{"txpackages", BCLog::TXPACKAGES},
- {"1", BCLog::ALL},
{"all", BCLog::ALL},
};
@@ -184,11 +182,8 @@ static const std::unordered_map<BCLog::LogFlags, std::string> LOG_CATEGORIES_BY_
[](const std::map<std::string, BCLog::LogFlags>& in) {
std::unordered_map<BCLog::LogFlags, std::string> out;
for (const auto& [k, v] : in) {
- switch (v) {
- case BCLog::NONE: out.emplace(BCLog::NONE, ""); break;
- case BCLog::ALL: out.emplace(BCLog::ALL, "all"); break;
- default: out.emplace(v, k);
- }
+ bool inserted{out.emplace(v, k).second};
+ assert(inserted);
}
return out;
}(LOG_CATEGORIES_BY_STR)
@@ -196,9 +191,12 @@ static const std::unordered_map<BCLog::LogFlags, std::string> LOG_CATEGORIES_BY_
bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
{
- if (str.empty()) {
+ if (str.empty() || str == "1") {
flag = BCLog::ALL;
return true;
+ } else if (str == "0") {
+ flag = BCLog::NONE;
+ return true;
}
auto it = LOG_CATEGORIES_BY_STR.find(str);
if (it != LOG_CATEGORIES_BY_STR.end()) {