mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
logging: make [cat:debug] and [info] implicit
This commit is contained in:
parent
c5c76dc615
commit
dfe98b6874
2 changed files with 21 additions and 18 deletions
|
@ -394,26 +394,29 @@ namespace BCLog {
|
||||||
|
|
||||||
std::string BCLog::Logger::GetLogPrefix(BCLog::LogFlags category, BCLog::Level level) const
|
std::string BCLog::Logger::GetLogPrefix(BCLog::LogFlags category, BCLog::Level level) const
|
||||||
{
|
{
|
||||||
if (category != LogFlags::NONE || level != Level::None) {
|
const bool has_category{category != LogFlags::NONE};
|
||||||
std::string s{"["};
|
|
||||||
|
|
||||||
if (category != LogFlags::NONE) {
|
if (!has_category && level == Level::None) return {};
|
||||||
s += LogCategoryToStr(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (category != LogFlags::NONE && level != Level::None) {
|
// If there is no category, Info is implied
|
||||||
// Only add separator if both flag and level are not NONE
|
if (!has_category && level == Level::Info) return {};
|
||||||
s += ":";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level != Level::None) {
|
std::string s{"["};
|
||||||
s += LogLevelToStr(level);
|
if (has_category) {
|
||||||
}
|
s += LogCategoryToStr(category);
|
||||||
|
|
||||||
s += "] ";
|
// If there is a category, Debug is implied
|
||||||
return s;
|
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)
|
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)
|
||||||
|
|
|
@ -94,11 +94,11 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintf_, LogSetup)
|
||||||
log_lines.push_back(log);
|
log_lines.push_back(log);
|
||||||
}
|
}
|
||||||
std::vector<std::string> expected = {
|
std::vector<std::string> expected = {
|
||||||
"[src1:1] [fn1] [net:debug] foo1: bar1",
|
"[src1:1] [fn1] [net] foo1: bar1",
|
||||||
"[src2:2] [fn2] [net] foo2: bar2",
|
"[src2:2] [fn2] [net] foo2: bar2",
|
||||||
"[src3:3] [fn3] [debug] foo3: bar3",
|
"[src3:3] [fn3] [debug] foo3: bar3",
|
||||||
"[src4:4] [fn4] foo4: bar4",
|
"[src4:4] [fn4] foo4: bar4",
|
||||||
"[src5:5] [fn5] [info] foo5: bar5",
|
"[src5:5] [fn5] foo5: bar5",
|
||||||
};
|
};
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
|
||||||
std::vector<std::string> expected = {
|
std::vector<std::string> expected = {
|
||||||
"foo5: bar5",
|
"foo5: bar5",
|
||||||
"[net] foo6: bar6",
|
"[net] foo6: bar6",
|
||||||
"[net:debug] foo7: bar7",
|
"[net] foo7: bar7",
|
||||||
"[net:info] foo8: bar8",
|
"[net:info] foo8: bar8",
|
||||||
"[net:warning] foo9: bar9",
|
"[net:warning] foo9: bar9",
|
||||||
"[net:error] foo10: bar10",
|
"[net:error] foo10: bar10",
|
||||||
|
|
Loading…
Add table
Reference in a new issue