mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
logging: Drop BCLog::Level::None
Now that Info-level logging is always logged, there is no further need for the "None" level, so remove it.
This commit is contained in:
parent
ab34dc6012
commit
667ce3e329
3 changed files with 12 additions and 27 deletions
|
@ -215,8 +215,6 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level)
|
|||
return "warning";
|
||||
case BCLog::Level::Error:
|
||||
return "error";
|
||||
case BCLog::Level::None:
|
||||
return "";
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
@ -307,8 +305,6 @@ static std::optional<BCLog::Level> GetLogLevel(const std::string& level_str)
|
|||
return BCLog::Level::Warning;
|
||||
} else if (level_str == "error") {
|
||||
return BCLog::Level::Error;
|
||||
} else if (level_str == "none") {
|
||||
return BCLog::Level::None;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -396,20 +392,17 @@ std::string BCLog::Logger::GetLogPrefix(BCLog::LogFlags category, BCLog::Level l
|
|||
{
|
||||
const bool has_category{category != LogFlags::NONE};
|
||||
|
||||
if (!has_category && level == Level::None) return {};
|
||||
|
||||
// If there is no category, Info is implied
|
||||
if (!has_category && level == Level::Info) return {};
|
||||
|
||||
std::string s{"["};
|
||||
if (has_category) {
|
||||
s += LogCategoryToStr(category);
|
||||
|
||||
// If there is a category, Debug is implied
|
||||
if (level == Level::Debug) level = Level::None;
|
||||
}
|
||||
|
||||
if (level != Level::None) {
|
||||
if (!has_category || level != Level::Debug) {
|
||||
// If there is a category, Debug is implied, so don't add the level
|
||||
|
||||
// Only add separator if we have a category
|
||||
if (has_category) s += ":";
|
||||
s += Logger::LogLevelToStr(level);
|
||||
|
|
|
@ -77,7 +77,6 @@ namespace BCLog {
|
|||
Info, // Default
|
||||
Warning,
|
||||
Error,
|
||||
None, // Internal use only
|
||||
};
|
||||
constexpr auto DEFAULT_LOG_LEVEL{Level::Debug};
|
||||
|
||||
|
@ -236,22 +235,14 @@ static inline void LogPrintf_(const std::string& logging_function, const std::st
|
|||
#define LogPrintLevel_(category, level, ...) LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)
|
||||
|
||||
// Log unconditionally.
|
||||
#define LogPrintf(...) LogPrintLevel_(BCLog::LogFlags::NONE, BCLog::Level::None, __VA_ARGS__)
|
||||
#define LogPrintf(...) LogPrintLevel_(BCLog::LogFlags::NONE, BCLog::Level::Info, __VA_ARGS__)
|
||||
|
||||
// Log unconditionally, prefixing the output with the passed category name.
|
||||
#define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__)
|
||||
#define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::Info, __VA_ARGS__)
|
||||
|
||||
// Use a macro instead of a function for conditional logging to prevent
|
||||
// evaluating arguments when logging for the category is not enabled.
|
||||
|
||||
// Log conditionally, prefixing the output with the passed category name.
|
||||
#define LogPrint(category, ...) \
|
||||
do { \
|
||||
if (LogAcceptCategory((category), BCLog::Level::Debug)) { \
|
||||
LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Log conditionally, prefixing the output with the passed category name and severity level.
|
||||
#define LogPrintLevel(category, level, ...) \
|
||||
do { \
|
||||
|
@ -260,6 +251,9 @@ static inline void LogPrintf_(const std::string& logging_function, const std::st
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
// Log conditionally, prefixing the output with the passed category name.
|
||||
#define LogPrint(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__)
|
||||
|
||||
template <typename... Args>
|
||||
bool error(const char* fmt, const Args&... args)
|
||||
{
|
||||
|
|
|
@ -84,10 +84,9 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintf_, LogSetup)
|
|||
{
|
||||
LogInstance().m_log_sourcelocations = true;
|
||||
LogPrintf_("fn1", "src1", 1, BCLog::LogFlags::NET, BCLog::Level::Debug, "foo1: %s\n", "bar1");
|
||||
LogPrintf_("fn2", "src2", 2, BCLog::LogFlags::NET, BCLog::Level::None, "foo2: %s\n", "bar2");
|
||||
LogPrintf_("fn2", "src2", 2, BCLog::LogFlags::NET, BCLog::Level::Info, "foo2: %s\n", "bar2");
|
||||
LogPrintf_("fn3", "src3", 3, BCLog::LogFlags::NONE, BCLog::Level::Debug, "foo3: %s\n", "bar3");
|
||||
LogPrintf_("fn4", "src4", 4, BCLog::LogFlags::NONE, BCLog::Level::None, "foo4: %s\n", "bar4");
|
||||
LogPrintf_("fn5", "src5", 5, BCLog::LogFlags::NONE, BCLog::Level::Info, "foo5: %s\n", "bar5");
|
||||
LogPrintf_("fn4", "src4", 4, BCLog::LogFlags::NONE, BCLog::Level::Info, "foo4: %s\n", "bar4");
|
||||
std::ifstream file{tmp_log_path};
|
||||
std::vector<std::string> log_lines;
|
||||
for (std::string log; std::getline(file, log);) {
|
||||
|
@ -95,10 +94,9 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintf_, LogSetup)
|
|||
}
|
||||
std::vector<std::string> expected = {
|
||||
"[src1:1] [fn1] [net] foo1: bar1",
|
||||
"[src2:2] [fn2] [net] foo2: bar2",
|
||||
"[src2:2] [fn2] [net:info] foo2: bar2",
|
||||
"[src3:3] [fn3] [debug] foo3: bar3",
|
||||
"[src4:4] [fn4] foo4: bar4",
|
||||
"[src5:5] [fn5] foo5: bar5",
|
||||
};
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
|
||||
}
|
||||
|
@ -124,7 +122,7 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
|
|||
"[net:info] foo8: bar8",
|
||||
"[net:warning] foo9: bar9",
|
||||
"[net:error] foo10: bar10",
|
||||
"[validation] foo11: bar11",
|
||||
"[validation:info] foo11: bar11",
|
||||
};
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue