diff options
author | klementtan <klementtan@gmail.com> | 2022-08-18 11:02:54 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2022-08-20 11:31:28 +0200 |
commit | 98a1f9c68744074f29fa5fa67514218b5ee9edc4 (patch) | |
tree | 7ec8128c78f68766f55047f842e796e69a2650e3 /src/test/logging_tests.cpp | |
parent | 9c7507bf76e79da99766a69df939520ea0a125d1 (diff) |
Unit test coverage for log severity levels
Co-authored-by: "Jon Atack <jon@atack.com>"
Diffstat (limited to 'src/test/logging_tests.cpp')
-rw-r--r-- | src/test/logging_tests.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp index 00c6107c5a..c827b4eec5 100644 --- a/src/test/logging_tests.cpp +++ b/src/test/logging_tests.cpp @@ -161,4 +161,37 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros_CategoryName, LogSetup) BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end()); } +BOOST_FIXTURE_TEST_CASE(logging_SeverityLevels, LogSetup) +{ + LogInstance().EnableCategory(BCLog::LogFlags::ALL); + + LogInstance().SetLogLevel(BCLog::Level::Info); + LogInstance().SetCategoryLogLevel(/*category_str=*/"net", /*level_str=*/"info"); + + // Global log level + LogPrintLevel(BCLog::HTTP, BCLog::Level::Info, "foo1: %s\n", "bar1"); + LogPrintLevel(BCLog::MEMPOOL, BCLog::Level::Debug, "foo2: %s. This log level is lower than the global one.\n", "bar2"); + LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Warning, "foo3: %s\n", "bar3"); + LogPrintLevel(BCLog::RPC, BCLog::Level::Error, "foo4: %s\n", "bar4"); + + // Category-specific log level + LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "foo5: %s\n", "bar5"); + LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "foo6: %s. This log level is lower than the category-specific one.\n", "bar6"); + LogPrintLevel(BCLog::NET, BCLog::Level::Error, "foo7: %s\n", "bar7"); + + std::vector<std::string> expected = { + "[http:info] foo1: bar1", + "[validation:warning] foo3: bar3", + "[rpc:error] foo4: bar4", + "[net:warning] foo5: bar5", + "[net:error] foo7: bar7", + }; + 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); + } + BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end()); +} + BOOST_AUTO_TEST_SUITE_END() |