aboutsummaryrefslogtreecommitdiff
path: root/src/test/logging_tests.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2023-08-22 13:23:38 +1000
committerAnthony Towns <aj@erisian.com.au>2023-12-20 15:59:48 +1000
commitf7ce5ac08c669ac763e275bb7c82dcfb2b1b6c33 (patch)
tree2bc830fec16764c0196930f3576081c7e3631590 /src/test/logging_tests.cpp
parentfbd7642c8e5b70327e019382320f5ef0a651ecc5 (diff)
logging: add LogError, LogWarning, LogInfo, LogDebug, LogTrace
These provide simple and clear ways to write the most common logging operations: LogInfo("msg"); LogDebug(BCLog::LogFlags::NET, "msg"); LogError("msg"); LogWarning("msg"); LogTrace(BCLog::LogFlags::NET, "msg"); For cases where the level cannot be hardcoded, LogPrintLevel(category, level, ...) remains available.
Diffstat (limited to 'src/test/logging_tests.cpp')
-rw-r--r--src/test/logging_tests.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp
index abc878c5a5..88e3ec94b7 100644
--- a/src/test/logging_tests.cpp
+++ b/src/test/logging_tests.cpp
@@ -105,10 +105,11 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintf_, LogSetup)
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
}
-BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
+BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacrosDeprecated, LogSetup)
{
LogPrintf("foo5: %s\n", "bar5");
LogPrint(BCLog::NET, "foo6: %s\n", "bar6");
+ LogPrintLevel(BCLog::NET, BCLog::Level::Trace, "foo4: %s\n", "bar4"); // not logged
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "foo7: %s\n", "bar7");
LogPrintLevel(BCLog::NET, BCLog::Level::Info, "foo8: %s\n", "bar8");
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "foo9: %s\n", "bar9");
@@ -131,6 +132,27 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
}
+BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
+{
+ LogTrace(BCLog::NET, "foo6: %s\n", "bar6"); // not logged
+ LogDebug(BCLog::NET, "foo7: %s\n", "bar7");
+ LogInfo("foo8: %s\n", "bar8");
+ LogWarning("foo9: %s\n", "bar9");
+ LogError("foo10: %s\n", "bar10");
+ std::ifstream file{tmp_log_path};
+ std::vector<std::string> log_lines;
+ for (std::string log; std::getline(file, log);) {
+ log_lines.push_back(log);
+ }
+ std::vector<std::string> expected = {
+ "[net] foo7: bar7",
+ "foo8: bar8",
+ "[warning] foo9: bar9",
+ "[error] foo10: bar10",
+ };
+ BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
+}
+
BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros_CategoryName, LogSetup)
{
LogInstance().EnableCategory(BCLog::LogFlags::ALL);