|
2 | 2 | // Distributed under the MIT software license, see the accompanying
|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
| 5 | +#include <init/common.h> |
5 | 6 | #include <logging.h>
|
6 | 7 | #include <logging/timer.h>
|
7 | 8 | #include <test/util/setup_common.h>
|
|
18 | 19 |
|
19 | 20 | BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup)
|
20 | 21 |
|
| 22 | +static void ResetLogger() |
| 23 | +{ |
| 24 | + LogInstance().SetLogLevel(BCLog::DEFAULT_LOG_LEVEL); |
| 25 | + LogInstance().SetCategoryLogLevel({}); |
| 26 | +} |
| 27 | + |
21 | 28 | struct LogSetup : public BasicTestingSetup {
|
22 | 29 | fs::path prev_log_path;
|
23 | 30 | fs::path tmp_log_path;
|
@@ -194,4 +201,59 @@ BOOST_FIXTURE_TEST_CASE(logging_SeverityLevels, LogSetup)
|
194 | 201 | BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
|
195 | 202 | }
|
196 | 203 |
|
| 204 | +BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup) |
| 205 | +{ |
| 206 | + // Set global log level |
| 207 | + { |
| 208 | + ResetLogger(); |
| 209 | + ArgsManager args; |
| 210 | + args.AddArg("-loglevel", "...", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); |
| 211 | + const char* argv_test[] = {"bitcoind", "-loglevel=debug"}; |
| 212 | + std::string err; |
| 213 | + BOOST_REQUIRE(args.ParseParameters(2, argv_test, err)); |
| 214 | + init::SetLoggingLevel(args); |
| 215 | + BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::Level::Debug); |
| 216 | + } |
| 217 | + |
| 218 | + // Set category-specific log level |
| 219 | + { |
| 220 | + ResetLogger(); |
| 221 | + ArgsManager args; |
| 222 | + args.AddArg("-loglevel", "...", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); |
| 223 | + const char* argv_test[] = {"bitcoind", "-loglevel=net:debug"}; |
| 224 | + std::string err; |
| 225 | + BOOST_REQUIRE(args.ParseParameters(2, argv_test, err)); |
| 226 | + init::SetLoggingLevel(args); |
| 227 | + BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::DEFAULT_LOG_LEVEL); |
| 228 | + |
| 229 | + const auto& category_levels{LogInstance().CategoryLevels()}; |
| 230 | + const auto net_it{category_levels.find(BCLog::LogFlags::NET)}; |
| 231 | + BOOST_REQUIRE(net_it != category_levels.end()); |
| 232 | + BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Debug); |
| 233 | + } |
| 234 | + |
| 235 | + // Set both global log level and category-specific log level |
| 236 | + { |
| 237 | + ResetLogger(); |
| 238 | + ArgsManager args; |
| 239 | + args.AddArg("-loglevel", "...", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); |
| 240 | + const char* argv_test[] = {"bitcoind", "-loglevel=debug", "-loglevel=net:debug", "-loglevel=http:info"}; |
| 241 | + std::string err; |
| 242 | + BOOST_REQUIRE(args.ParseParameters(4, argv_test, err)); |
| 243 | + init::SetLoggingLevel(args); |
| 244 | + BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::Level::Debug); |
| 245 | + |
| 246 | + const auto& category_levels{LogInstance().CategoryLevels()}; |
| 247 | + BOOST_CHECK_EQUAL(category_levels.size(), 2); |
| 248 | + |
| 249 | + const auto net_it{category_levels.find(BCLog::LogFlags::NET)}; |
| 250 | + BOOST_CHECK(net_it != category_levels.end()); |
| 251 | + BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Debug); |
| 252 | + |
| 253 | + const auto http_it{category_levels.find(BCLog::LogFlags::HTTP)}; |
| 254 | + BOOST_CHECK(http_it != category_levels.end()); |
| 255 | + BOOST_CHECK_EQUAL(http_it->second, BCLog::Level::Info); |
| 256 | + } |
| 257 | +} |
| 258 | + |
197 | 259 | BOOST_AUTO_TEST_SUITE_END()
|
0 commit comments