1010#include < chrono>
1111#include < fstream>
1212#include < iostream>
13+ #include < unordered_map>
1314#include < utility>
1415#include < vector>
1516
@@ -25,21 +26,30 @@ struct LogSetup : public BasicTestingSetup {
2526 bool prev_log_timestamps;
2627 bool prev_log_threadnames;
2728 bool prev_log_sourcelocations;
29+ std::unordered_map<BCLog::LogFlags, BCLog::Level> prev_category_levels;
30+ BCLog::Level prev_log_level;
2831
2932 LogSetup () : prev_log_path{LogInstance ().m_file_path },
3033 tmp_log_path{m_args.GetDataDirBase () / " tmp_debug.log" },
3134 prev_reopen_file{LogInstance ().m_reopen_file },
3235 prev_print_to_file{LogInstance ().m_print_to_file },
3336 prev_log_timestamps{LogInstance ().m_log_timestamps },
3437 prev_log_threadnames{LogInstance ().m_log_threadnames },
35- prev_log_sourcelocations{LogInstance ().m_log_sourcelocations }
38+ prev_log_sourcelocations{LogInstance ().m_log_sourcelocations },
39+ prev_category_levels{LogInstance ().CategoryLevels ()},
40+ prev_log_level{LogInstance ().LogLevel ()}
3641 {
3742 LogInstance ().m_file_path = tmp_log_path;
3843 LogInstance ().m_reopen_file = true ;
3944 LogInstance ().m_print_to_file = true ;
4045 LogInstance ().m_log_timestamps = false ;
4146 LogInstance ().m_log_threadnames = false ;
42- LogInstance ().m_log_sourcelocations = true ;
47+
48+ // Prevent tests from failing when the line number of the logs changes.
49+ LogInstance ().m_log_sourcelocations = false ;
50+
51+ LogInstance ().SetLogLevel (BCLog::Level::Debug);
52+ LogInstance ().SetCategoryLogLevel ({});
4353 }
4454
4555 ~LogSetup ()
@@ -51,6 +61,8 @@ struct LogSetup : public BasicTestingSetup {
5161 LogInstance ().m_log_timestamps = prev_log_timestamps;
5262 LogInstance ().m_log_threadnames = prev_log_threadnames;
5363 LogInstance ().m_log_sourcelocations = prev_log_sourcelocations;
64+ LogInstance ().SetLogLevel (prev_log_level);
65+ LogInstance ().SetCategoryLogLevel (prev_category_levels);
5466 }
5567};
5668
@@ -74,6 +86,7 @@ BOOST_AUTO_TEST_CASE(logging_timer)
7486
7587BOOST_FIXTURE_TEST_CASE (logging_LogPrintf_, LogSetup)
7688{
89+ LogInstance ().m_log_sourcelocations = true ;
7790 LogPrintf_ (" fn1" , " src1" , 1 , BCLog::LogFlags::NET, BCLog::Level::Debug, " foo1: %s" , " bar1\n " );
7891 LogPrintf_ (" fn2" , " src2" , 2 , BCLog::LogFlags::NET, BCLog::Level::None, " foo2: %s" , " bar2\n " );
7992 LogPrintf_ (" fn3" , " src3" , 3 , BCLog::LogFlags::NONE, BCLog::Level::Debug, " foo3: %s" , " bar3\n " );
@@ -94,9 +107,6 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintf_, LogSetup)
94107
95108BOOST_FIXTURE_TEST_CASE (logging_LogPrintMacros, LogSetup)
96109{
97- // Prevent tests from failing when the line number of the following log calls changes.
98- LogInstance ().m_log_sourcelocations = false ;
99-
100110 LogPrintf (" foo5: %s\n " , " bar5" );
101111 LogPrint (BCLog::NET, " foo6: %s\n " , " bar6" );
102112 LogPrintLevel (BCLog::NET, BCLog::Level::Debug, " foo7: %s\n " , " bar7" );
@@ -123,16 +133,14 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
123133
124134BOOST_FIXTURE_TEST_CASE (logging_LogPrintMacros_CategoryName, LogSetup)
125135{
126- // Prevent tests from failing when the line number of the following log calls changes.
127- LogInstance ().m_log_sourcelocations = false ;
128136 LogInstance ().EnableCategory (BCLog::LogFlags::ALL);
129- const auto concated_categery_names = LogInstance ().LogCategoriesString ();
137+ const auto concatenated_category_names = LogInstance ().LogCategoriesString ();
130138 std::vector<std::pair<BCLog::LogFlags, std::string>> expected_category_names;
131- const auto category_names = SplitString (concated_categery_names , ' ,' );
139+ const auto category_names = SplitString (concatenated_category_names , ' ,' );
132140 for (const auto & category_name : category_names) {
133- BCLog::LogFlags category = BCLog::NONE ;
141+ BCLog::LogFlags category;
134142 const auto trimmed_category_name = TrimString (category_name);
135- BOOST_TEST (GetLogCategory (category, trimmed_category_name));
143+ BOOST_REQUIRE (GetLogCategory (category, trimmed_category_name));
136144 expected_category_names.emplace_back (category, trimmed_category_name);
137145 }
138146
0 commit comments