From 8c6f3bf1634533a0dd268dcf5929e49429640a09 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Wed, 3 Apr 2024 11:00:20 +0200 Subject: [PATCH] logging, refactor: minor encapsulation improvement and use BCLog::NONE instead of 0 * Make the standalone function `LogCategoryToStr()` private inside `logging.cpp` (aka `static`) - it is only used in that file. * Make the method `Logger::GetLogPrefix()` `private` - it is only used within the class. * Use `BCLog::NONE` to initialize `m_categories` instead of `0`. We later check whether it is `BCLog::NONE` (in `Logger::DefaultShrinkDebugFile()`). --- src/logging.cpp | 2 +- src/logging.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index 6aeab4dfb46..175eae2cc95 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -248,7 +248,7 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level) assert(false); } -std::string LogCategoryToStr(BCLog::LogFlags category) +static std::string LogCategoryToStr(BCLog::LogFlags category) { if (category == BCLog::ALL) { return "all"; diff --git a/src/logging.h b/src/logging.h index 91f919e8223..2ff58979cb3 100644 --- a/src/logging.h +++ b/src/logging.h @@ -119,7 +119,7 @@ namespace BCLog { std::atomic m_log_level{DEFAULT_LOG_LEVEL}; /** Log categories bitfield. */ - std::atomic m_categories{0}; + std::atomic m_categories{BCLog::NONE}; void FormatLogStrInPlace(std::string& str, LogFlags category, Level level, std::string_view source_file, int source_line, std::string_view logging_function, std::string_view threadname, SystemClock::time_point now, std::chrono::seconds mocktime) const; @@ -132,6 +132,8 @@ namespace BCLog { void LogPrintStr_(std::string_view str, std::string_view logging_function, std::string_view source_file, int source_line, BCLog::LogFlags category, BCLog::Level level) EXCLUSIVE_LOCKS_REQUIRED(m_cs); + std::string GetLogPrefix(LogFlags category, Level level) const; + public: bool m_print_to_console = false; bool m_print_to_file = false; @@ -145,8 +147,6 @@ namespace BCLog { fs::path m_file_path; std::atomic m_reopen_file{false}; - std::string GetLogPrefix(LogFlags category, Level level) const; - /** Send a string to the log output */ void LogPrintStr(std::string_view str, std::string_view logging_function, std::string_view source_file, int source_line, BCLog::LogFlags category, BCLog::Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs);