logging: Move GetLogCategory into Logger class
What changed, and why it matters
This commit is a simple code cleanup: it moves a helper function that converts a log category name into an internal flag from the global namespace into the Logger class. There is no change in behavior, no user-visible effect, and no security relevance.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors GetLogCategory(std::string_view) from a free function in the BCLog namespace into a static member of BCLog::Logger. Call sites and the declaration are updated accordingly. The function body is unchanged, and the test only updates the qualified name used to call it. This is a pure structural refactor with no functional or security impact.
Changed components
src/logging.cppsrc/logging.hsrc/test/logging_tests.cppInspect captured patch +5 / −5
diff --git a/src/logging.cpp b/src/logging.cpp
index 0edc970d..fc6dd1b8 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -224,7 +224,7 @@ static const std::unordered_map<BCLog::LogFlags, std::string> LOG_CATEGORIES_BY_
}(LOG_CATEGORIES_BY_STR)
};
-std::optional<BCLog::LogFlags> GetLogCategory(std::string_view str)
+std::optional<BCLog::LogFlags> BCLog::Logger::GetLogCategory(std::string_view str)
{
if (str.empty() || str == "1" || str == "all") {
return BCLog::ALL;
diff --git a/src/logging.h b/src/logging.h
index 9ff1c7ea..a727dc24 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -275,6 +275,9 @@ namespace BCLog {
static std::string LogLevelToStr(BCLog::Level level);
bool DefaultShrinkDebugFile() const;
+
+ //! Return log flag if str parses as a log category.
+ static std::optional<BCLog::LogFlags> GetLogCategory(std::string_view str);
};
} // namespace BCLog
@@ -286,7 +289,4 @@ static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level leve
return LogInstance().WillLogCategoryLevel(category, level);
}
-/// Return log flag if str parses as a log category.
-std::optional<BCLog::LogFlags> GetLogCategory(std::string_view str);
-
#endif // BITCOIN_LOGGING_H
diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp
index 550ef85c..5595fe16 100644
--- a/src/test/logging_tests.cpp
+++ b/src/test/logging_tests.cpp
@@ -166,7 +166,7 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros_CategoryName, LogSetup)
const auto category_names = SplitString(concatenated_category_names, ',');
for (const auto& category_name : category_names) {
const auto trimmed_category_name = TrimString(category_name);
- const auto category{*Assert(GetLogCategory(trimmed_category_name))};
+ const auto category{*Assert(BCLog::Logger::GetLogCategory(trimmed_category_name))};
expected_category_names.emplace_back(category, trimmed_category_name);
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.