From a9c295888b82c86ef4629aa2d9061ea152b48f20 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Fri, 12 May 2023 00:58:35 +0200 Subject: init: raise on invalid loglevel config option --- src/init/common.cpp | 7 ++++--- src/init/common.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/init') diff --git a/src/init/common.cpp b/src/init/common.cpp index 2c36d30fdf..b9c19725b1 100644 --- a/src/init/common.cpp +++ b/src/init/common.cpp @@ -59,24 +59,25 @@ void SetLoggingOptions(const ArgsManager& args) fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS); } -void SetLoggingLevel(const ArgsManager& args) +util::Result 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= 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=: 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=:. 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=:. Valid categories: %s. Valid loglevels: %s."), level_str, LogInstance().LogCategoriesString(), LogInstance().LogLevelsString())}; } } } } + return {}; } util::Result SetLoggingCategories(const ArgsManager& args) diff --git a/src/init/common.h b/src/init/common.h index 1c7bcf8671..b61a77c6d4 100644 --- a/src/init/common.h +++ b/src/init/common.h @@ -16,7 +16,7 @@ namespace init { void AddLoggingArgs(ArgsManager& args); void SetLoggingOptions(const ArgsManager& args); [[nodiscard]] util::Result SetLoggingCategories(const ArgsManager& args); -void SetLoggingLevel(const ArgsManager& args); +[[nodiscard]] util::Result SetLoggingLevel(const ArgsManager& args); bool StartLogging(const ArgsManager& args); void LogPackageVersion(); } // namespace init -- cgit v1.2.3