mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
init: raise on invalid loglevel config option
This commit is contained in:
parent
b0c3995393
commit
a9c295888b
4 changed files with 16 additions and 8 deletions
|
@ -952,7 +952,8 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
|
|||
// ********************************************************* Step 3: parameter-to-internal-flags
|
||||
auto result = init::SetLoggingCategories(args);
|
||||
if (!result) return InitError(util::ErrorString(result));
|
||||
init::SetLoggingLevel(args);
|
||||
result = init::SetLoggingLevel(args);
|
||||
if (!result) return InitError(util::ErrorString(result));
|
||||
|
||||
nConnectTimeout = args.GetIntArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
|
||||
if (nConnectTimeout <= 0) {
|
||||
|
|
|
@ -59,24 +59,25 @@ void SetLoggingOptions(const ArgsManager& args)
|
|||
fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
|
||||
}
|
||||
|
||||
void SetLoggingLevel(const ArgsManager& args)
|
||||
util::Result<void> SetLoggingLevel(const ArgsManager& args)
|
||||
{
|
||||
if (args.IsArgSet("-loglevel")) {
|
||||
for (const std::string& level_str : args.GetArgs("-loglevel")) {
|
||||
if (level_str.find_first_of(':', 3) == std::string::npos) {
|
||||
// user passed a global log level, i.e. -loglevel=<level>
|
||||
if (!LogInstance().SetLogLevel(level_str)) {
|
||||
InitWarning(strprintf(_("Unsupported global logging level -loglevel=%s. Valid values: %s."), level_str, LogInstance().LogLevelsString()));
|
||||
return util::Error{strprintf(_("Unsupported global logging level -loglevel=%s. Valid values: %s."), level_str, LogInstance().LogLevelsString())};
|
||||
}
|
||||
} else {
|
||||
// user passed a category-specific log level, i.e. -loglevel=<category>:<level>
|
||||
const auto& toks = SplitString(level_str, ':');
|
||||
if (!(toks.size() == 2 && LogInstance().SetCategoryLogLevel(toks[0], toks[1]))) {
|
||||
InitWarning(strprintf(_("Unsupported category-specific logging level -loglevel=%s. Expected -loglevel=<category>:<loglevel>. Valid categories: %s. Valid loglevels: %s."), level_str, LogInstance().LogCategoriesString(), LogInstance().LogLevelsString()));
|
||||
return util::Error{strprintf(_("Unsupported category-specific logging level -loglevel=%s. Expected -loglevel=<category>:<loglevel>. Valid categories: %s. Valid loglevels: %s."), level_str, LogInstance().LogCategoriesString(), LogInstance().LogLevelsString())};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
util::Result<void> SetLoggingCategories(const ArgsManager& args)
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace init {
|
|||
void AddLoggingArgs(ArgsManager& args);
|
||||
void SetLoggingOptions(const ArgsManager& args);
|
||||
[[nodiscard]] util::Result<void> SetLoggingCategories(const ArgsManager& args);
|
||||
void SetLoggingLevel(const ArgsManager& args);
|
||||
[[nodiscard]] util::Result<void> SetLoggingLevel(const ArgsManager& args);
|
||||
bool StartLogging(const ArgsManager& args);
|
||||
void LogPackageVersion();
|
||||
} // namespace init
|
||||
|
|
|
@ -200,7 +200,9 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
|
|||
const char* argv_test[] = {"bitcoind", "-loglevel=debug"};
|
||||
std::string err;
|
||||
BOOST_REQUIRE(args.ParseParameters(2, argv_test, err));
|
||||
init::SetLoggingLevel(args);
|
||||
|
||||
auto result = init::SetLoggingLevel(args);
|
||||
BOOST_REQUIRE(result);
|
||||
BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::Level::Debug);
|
||||
}
|
||||
|
||||
|
@ -212,7 +214,9 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
|
|||
const char* argv_test[] = {"bitcoind", "-loglevel=net:trace"};
|
||||
std::string err;
|
||||
BOOST_REQUIRE(args.ParseParameters(2, argv_test, err));
|
||||
init::SetLoggingLevel(args);
|
||||
|
||||
auto result = init::SetLoggingLevel(args);
|
||||
BOOST_REQUIRE(result);
|
||||
BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::DEFAULT_LOG_LEVEL);
|
||||
|
||||
const auto& category_levels{LogInstance().CategoryLevels()};
|
||||
|
@ -229,7 +233,9 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
|
|||
const char* argv_test[] = {"bitcoind", "-loglevel=debug", "-loglevel=net:trace", "-loglevel=http:info"};
|
||||
std::string err;
|
||||
BOOST_REQUIRE(args.ParseParameters(4, argv_test, err));
|
||||
init::SetLoggingLevel(args);
|
||||
|
||||
auto result = init::SetLoggingLevel(args);
|
||||
BOOST_REQUIRE(result);
|
||||
BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::Level::Debug);
|
||||
|
||||
const auto& category_levels{LogInstance().CategoryLevels()};
|
||||
|
|
Loading…
Add table
Reference in a new issue