NIT: This change introduces a logging side-effect to a (almost) pure table lookup.
The diff below moves the warning out to the action sites, keeps GetLogCategory pure and removes the need to return BCLog::NONE;
In my change GetLogCategory stays a plain table lookup returning nullopt for unknown strings, and each of EnableCategory / DisableCategory / SetCategoryLogLevel falls through to WarnIfDeprecatedCategory(str) on a miss.
Not a blocker, this is temporary code after all but still.
diff --git a/src/logging.cpp b/src/logging.cpp
index 701e063dce..c45dd74ad9 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -125,6 +125,15 @@ void BCLog::Logger::DisableLogging()
StartLogging();
}
+static bool WarnIfDeprecatedCategory(std::string_view str)
+{
+ if (str == "libevent") {
+ LogWarning("The logging category `%s` is deprecated, can not be enabled, and will be removed in a future version", str);
+ return true;
+ }
+ return false;
+}
+
void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
{
m_categories |= flag;
@@ -136,7 +145,7 @@ bool BCLog::Logger::EnableCategory(std::string_view str)
EnableCategory(*flag);
return true;
}
- return false;
+ return WarnIfDeprecatedCategory(str);
}
void BCLog::Logger::DisableCategory(BCLog::LogFlags flag)
@@ -150,7 +159,7 @@ bool BCLog::Logger::DisableCategory(std::string_view str)
DisableCategory(*flag);
return true;
}
- return false;
+ return WarnIfDeprecatedCategory(str);
}
bool BCLog::Logger::WillLogCategory(BCLog::LogFlags category) const
@@ -232,10 +241,6 @@ std::optional<BCLog::LogFlags> BCLog::Logger::GetLogCategory(std::string_view st
if (it != LOG_CATEGORIES_BY_STR.end()) {
return it->second;
}
- if (str == "libevent") {
- LogWarning("The logging category `%s` is deprecated, can not be enabled, and will be removed in a future version", str);
- return BCLog::NONE;
- }
return std::nullopt;
}
@@ -605,7 +610,7 @@ bool BCLog::Logger::SetLogLevel(std::string_view level_str)
bool BCLog::Logger::SetCategoryLogLevel(std::string_view category_str, std::string_view level_str)
{
const auto flag{GetLogCategory(category_str)};
- if (!flag) return false;
+ if (!flag) return WarnIfDeprecatedCategory(category_str);
const auto level = GetLogLevel(level_str);
if (!level.has_value() || level.value() > MAX_USER_SETABLE_SEVERITY_LEVEL) return false;