diff options
author | Anthony Towns <aj@erisian.com.au> | 2023-08-22 14:17:53 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2023-12-15 11:03:25 +1000 |
commit | dfe98b6874da04e45f68d17575c1e8a5431ca9bc (patch) | |
tree | e3d1cfe19e942bf86beede6986a1e74b866ce151 /src/logging.cpp | |
parent | c5c76dc615677d226c9f6b3f2b66d833315d40da (diff) | |
download | bitcoin-dfe98b6874da04e45f68d17575c1e8a5431ca9bc.tar.xz |
logging: make [cat:debug] and [info] implicit
Diffstat (limited to 'src/logging.cpp')
-rw-r--r-- | src/logging.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/logging.cpp b/src/logging.cpp index c4bd221e04..b23a6f96eb 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -394,26 +394,29 @@ namespace BCLog { std::string BCLog::Logger::GetLogPrefix(BCLog::LogFlags category, BCLog::Level level) const { - if (category != LogFlags::NONE || level != Level::None) { - std::string s{"["}; + const bool has_category{category != LogFlags::NONE}; - if (category != LogFlags::NONE) { - s += LogCategoryToStr(category); - } + if (!has_category && level == Level::None) return {}; - if (category != LogFlags::NONE && level != Level::None) { - // Only add separator if both flag and level are not NONE - s += ":"; - } + // If there is no category, Info is implied + if (!has_category && level == Level::Info) return {}; - if (level != Level::None) { - s += LogLevelToStr(level); - } + std::string s{"["}; + if (has_category) { + s += LogCategoryToStr(category); - s += "] "; - return s; + // If there is a category, Debug is implied + if (level == Level::Debug) level = Level::None; } - return {}; + + if (level != Level::None) { + // Only add separator if we have a category + if (has_category) s += ":"; + s += Logger::LogLevelToStr(level); + } + + s += "] "; + return s; } void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level) |