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:
0--- a/src/logging.cpp
1+++ b/src/logging.cpp
2@@ -142,7 +142,6 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const
3 }
4
5 static const std::map<std::string, BCLog::LogFlags> LOG_CATEGORIES_BY_STR{
6- {"0", BCLog::NONE},
7 {"", BCLog::NONE},
8 {"net", BCLog::NET},
9 {"tor", BCLog::TOR},
10@@ -175,7 +174,6 @@ static const std::map<std::string, BCLog::LogFlags> LOG_CATEGORIES_BY_STR{
11 {"txreconciliation", BCLog::TXRECONCILIATION},
12 {"scan", BCLog::SCAN},
13 {"txpackages", BCLog::TXPACKAGES},
14- {"1", BCLog::ALL},
15 {"all", BCLog::ALL},
16 };
17
18@@ -184,11 +182,8 @@ static const std::unordered_map<BCLog::LogFlags, std::string> LOG_CATEGORIES_BY_
19 [](const std::map<std::string, BCLog::LogFlags>& in) {
20 std::unordered_map<BCLog::LogFlags, std::string> out;
21 for (const auto& [k, v] : in) {
22- switch (v) {
23- case BCLog::NONE: out.emplace(BCLog::NONE, ""); break;
24- case BCLog::ALL: out.emplace(BCLog::ALL, "all"); break;
25- default: out.emplace(v, k);
26- }
27+ bool inserted{out.emplace(v, k).second};
28+ assert(inserted);
29 }
30 return out;
31 }(LOG_CATEGORIES_BY_STR)
32@@ -196,9 +191,12 @@ static const std::unordered_map<BCLog::LogFlags, std::string> LOG_CATEGORIES_BY_
33
34 bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
35 {
36- if (str.empty()) {
37+ if (str.empty() || str == "1") {
38 flag = BCLog::ALL;
39 return true;
40+ } else if (str == "0") {
41+ flag = BCLog::NONE;
42+ return true;
43 }
44 auto it = LOG_CATEGORIES_BY_STR.find(str);
45 if (it != LOG_CATEGORIES_BY_STR.end()) {