@@ -161,4 +161,37 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros_CategoryName, LogSetup)
161
161
BOOST_CHECK_EQUAL_COLLECTIONS (log_lines.begin (), log_lines.end (), expected.begin (), expected.end ());
162
162
}
163
163
164
+ BOOST_FIXTURE_TEST_CASE (logging_SeverityLevels, LogSetup)
165
+ {
166
+ LogInstance ().EnableCategory (BCLog::LogFlags::ALL);
167
+
168
+ LogInstance ().SetLogLevel (BCLog::Level::Info);
169
+ LogInstance ().SetCategoryLogLevel (/* category_str=*/ " net" , /* level_str=*/ " info" );
170
+
171
+ // Global log level
172
+ LogPrintLevel (BCLog::HTTP, BCLog::Level::Info, " foo1: %s\n " , " bar1" );
173
+ LogPrintLevel (BCLog::MEMPOOL, BCLog::Level::Debug, " foo2: %s. This log level is lower than the global one.\n " , " bar2" );
174
+ LogPrintLevel (BCLog::VALIDATION, BCLog::Level::Warning, " foo3: %s\n " , " bar3" );
175
+ LogPrintLevel (BCLog::RPC, BCLog::Level::Error, " foo4: %s\n " , " bar4" );
176
+
177
+ // Category-specific log level
178
+ LogPrintLevel (BCLog::NET, BCLog::Level::Warning, " foo5: %s\n " , " bar5" );
179
+ LogPrintLevel (BCLog::NET, BCLog::Level::Debug, " foo6: %s. This log level is lower than the category-specific one.\n " , " bar6" );
180
+ LogPrintLevel (BCLog::NET, BCLog::Level::Error, " foo7: %s\n " , " bar7" );
181
+
182
+ std::vector<std::string> expected = {
183
+ " [http:info] foo1: bar1" ,
184
+ " [validation:warning] foo3: bar3" ,
185
+ " [rpc:error] foo4: bar4" ,
186
+ " [net:warning] foo5: bar5" ,
187
+ " [net:error] foo7: bar7" ,
188
+ };
189
+ std::ifstream file{tmp_log_path};
190
+ std::vector<std::string> log_lines;
191
+ for (std::string log; std::getline (file, log);) {
192
+ log_lines.push_back (log);
193
+ }
194
+ BOOST_CHECK_EQUAL_COLLECTIONS (log_lines.begin (), log_lines.end (), expected.begin (), expected.end ());
195
+ }
196
+
164
197
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments