mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -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
|
// ********************************************************* Step 3: parameter-to-internal-flags
|
||||||
auto result = init::SetLoggingCategories(args);
|
auto result = init::SetLoggingCategories(args);
|
||||||
if (!result) return InitError(util::ErrorString(result));
|
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);
|
nConnectTimeout = args.GetIntArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
|
||||||
if (nConnectTimeout <= 0) {
|
if (nConnectTimeout <= 0) {
|
||||||
|
|
|
@ -59,24 +59,25 @@ void SetLoggingOptions(const ArgsManager& args)
|
||||||
fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
|
fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetLoggingLevel(const ArgsManager& args)
|
util::Result<void> SetLoggingLevel(const ArgsManager& args)
|
||||||
{
|
{
|
||||||
if (args.IsArgSet("-loglevel")) {
|
if (args.IsArgSet("-loglevel")) {
|
||||||
for (const std::string& level_str : args.GetArgs("-loglevel")) {
|
for (const std::string& level_str : args.GetArgs("-loglevel")) {
|
||||||
if (level_str.find_first_of(':', 3) == std::string::npos) {
|
if (level_str.find_first_of(':', 3) == std::string::npos) {
|
||||||
// user passed a global log level, i.e. -loglevel=<level>
|
// user passed a global log level, i.e. -loglevel=<level>
|
||||||
if (!LogInstance().SetLogLevel(level_str)) {
|
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 {
|
} else {
|
||||||
// user passed a category-specific log level, i.e. -loglevel=<category>:<level>
|
// user passed a category-specific log level, i.e. -loglevel=<category>:<level>
|
||||||
const auto& toks = SplitString(level_str, ':');
|
const auto& toks = SplitString(level_str, ':');
|
||||||
if (!(toks.size() == 2 && LogInstance().SetCategoryLogLevel(toks[0], toks[1]))) {
|
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)
|
util::Result<void> SetLoggingCategories(const ArgsManager& args)
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace init {
|
||||||
void AddLoggingArgs(ArgsManager& args);
|
void AddLoggingArgs(ArgsManager& args);
|
||||||
void SetLoggingOptions(const ArgsManager& args);
|
void SetLoggingOptions(const ArgsManager& args);
|
||||||
[[nodiscard]] util::Result<void> SetLoggingCategories(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);
|
bool StartLogging(const ArgsManager& args);
|
||||||
void LogPackageVersion();
|
void LogPackageVersion();
|
||||||
} // namespace init
|
} // namespace init
|
||||||
|
|
|
@ -200,7 +200,9 @@ BOOST_FIXTURE_TEST_CASE(logging_Conf, LogSetup)
|
||||||
const char* argv_test[] = {"bitcoind", "-loglevel=debug"};
|
const char* argv_test[] = {"bitcoind", "-loglevel=debug"};
|
||||||
std::string err;
|
std::string err;
|
||||||
BOOST_REQUIRE(args.ParseParameters(2, argv_test, 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);
|
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"};
|
const char* argv_test[] = {"bitcoind", "-loglevel=net:trace"};
|
||||||
std::string err;
|
std::string err;
|
||||||
BOOST_REQUIRE(args.ParseParameters(2, argv_test, 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);
|
BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::DEFAULT_LOG_LEVEL);
|
||||||
|
|
||||||
const auto& category_levels{LogInstance().CategoryLevels()};
|
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"};
|
const char* argv_test[] = {"bitcoind", "-loglevel=debug", "-loglevel=net:trace", "-loglevel=http:info"};
|
||||||
std::string err;
|
std::string err;
|
||||||
BOOST_REQUIRE(args.ParseParameters(4, argv_test, 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);
|
BOOST_CHECK_EQUAL(LogInstance().LogLevel(), BCLog::Level::Debug);
|
||||||
|
|
||||||
const auto& category_levels{LogInstance().CategoryLevels()};
|
const auto& category_levels{LogInstance().CategoryLevels()};
|
||||||
|
|
Loading…
Add table
Reference in a new issue