10
10
#include < chrono>
11
11
#include < fstream>
12
12
#include < iostream>
13
+ #include < unordered_map>
13
14
#include < utility>
14
15
#include < vector>
15
16
@@ -25,21 +26,30 @@ struct LogSetup : public BasicTestingSetup {
25
26
bool prev_log_timestamps;
26
27
bool prev_log_threadnames;
27
28
bool prev_log_sourcelocations;
29
+ std::unordered_map<BCLog::LogFlags, BCLog::Level> prev_category_levels;
30
+ BCLog::Level prev_log_level;
28
31
29
32
LogSetup () : prev_log_path{LogInstance ().m_file_path },
30
33
tmp_log_path{m_args.GetDataDirBase () / " tmp_debug.log" },
31
34
prev_reopen_file{LogInstance ().m_reopen_file },
32
35
prev_print_to_file{LogInstance ().m_print_to_file },
33
36
prev_log_timestamps{LogInstance ().m_log_timestamps },
34
37
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 ()}
36
41
{
37
42
LogInstance ().m_file_path = tmp_log_path;
38
43
LogInstance ().m_reopen_file = true ;
39
44
LogInstance ().m_print_to_file = true ;
40
45
LogInstance ().m_log_timestamps = false ;
41
46
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 ({});
43
53
}
44
54
45
55
~LogSetup ()
@@ -51,6 +61,8 @@ struct LogSetup : public BasicTestingSetup {
51
61
LogInstance ().m_log_timestamps = prev_log_timestamps;
52
62
LogInstance ().m_log_threadnames = prev_log_threadnames;
53
63
LogInstance ().m_log_sourcelocations = prev_log_sourcelocations;
64
+ LogInstance ().SetLogLevel (prev_log_level);
65
+ LogInstance ().SetCategoryLogLevel (prev_category_levels);
54
66
}
55
67
};
56
68
@@ -74,6 +86,7 @@ BOOST_AUTO_TEST_CASE(logging_timer)
74
86
75
87
BOOST_FIXTURE_TEST_CASE (logging_LogPrintf_, LogSetup)
76
88
{
89
+ LogInstance ().m_log_sourcelocations = true ;
77
90
LogPrintf_ (" fn1" , " src1" , 1 , BCLog::LogFlags::NET, BCLog::Level::Debug, " foo1: %s" , " bar1\n " );
78
91
LogPrintf_ (" fn2" , " src2" , 2 , BCLog::LogFlags::NET, BCLog::Level::None, " foo2: %s" , " bar2\n " );
79
92
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)
94
107
95
108
BOOST_FIXTURE_TEST_CASE (logging_LogPrintMacros, LogSetup)
96
109
{
97
- // Prevent tests from failing when the line number of the following log calls changes.
98
- LogInstance ().m_log_sourcelocations = false ;
99
-
100
110
LogPrintf (" foo5: %s\n " , " bar5" );
101
111
LogPrint (BCLog::NET, " foo6: %s\n " , " bar6" );
102
112
LogPrintLevel (BCLog::NET, BCLog::Level::Debug, " foo7: %s\n " , " bar7" );
@@ -123,16 +133,14 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
123
133
124
134
BOOST_FIXTURE_TEST_CASE (logging_LogPrintMacros_CategoryName, LogSetup)
125
135
{
126
- // Prevent tests from failing when the line number of the following log calls changes.
127
- LogInstance ().m_log_sourcelocations = false ;
128
136
LogInstance ().EnableCategory (BCLog::LogFlags::ALL);
129
- const auto concated_categery_names = LogInstance ().LogCategoriesString ();
137
+ const auto concatenated_category_names = LogInstance ().LogCategoriesString ();
130
138
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 , ' ,' );
132
140
for (const auto & category_name : category_names) {
133
- BCLog::LogFlags category = BCLog::NONE ;
141
+ BCLog::LogFlags category;
134
142
const auto trimmed_category_name = TrimString (category_name);
135
- BOOST_TEST (GetLogCategory (category, trimmed_category_name));
143
+ BOOST_REQUIRE (GetLogCategory (category, trimmed_category_name));
136
144
expected_category_names.emplace_back (category, trimmed_category_name);
137
145
}
138
146
0 commit comments