diff --git a/external/oxen-logging b/external/oxen-logging index 44b6b7834..98a8882c8 160000 --- a/external/oxen-logging +++ b/external/oxen-logging @@ -1 +1 @@ -Subproject commit 44b6b7834bb0eee37f32bff6b9ae8bbbd4c5eb89 +Subproject commit 98a8882c81aa046fbadc0571fcea7bf92ed20154 diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 3ea4d970b..4ca1625c1 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -1099,13 +1099,7 @@ namespace llarp "logging", "type", DefaultLogType, - [this](std::string arg) { - auto type = log::type_from_string(arg); - if (type == log::Type::Unknown) - throw std::invalid_argument{fmt::format("invalid log type: {}", arg)}; - - m_logType = type; - }, + [this](std::string arg) { m_logType = log::type_from_string(arg); }, Comment{ "Log type (format). Valid options are:", " print - print logs to standard output", @@ -1117,13 +1111,7 @@ namespace llarp "logging", "level", DefaultLogLevel, - [this](std::string arg) { - std::optional level = log::level_from_string(arg); - if (not level) - throw std::invalid_argument{fmt::format("invalid log level value: {}", arg)}; - - m_logLevel = *level; - }, + [this](std::string arg) { m_logLevel = log::level_from_string(arg); }, Comment{ "Minimum log level to print. Logging below this level will be ignored.", "Valid log levels, in ascending order, are:", diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index 8d96ab71b..22385086b 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -210,7 +210,7 @@ namespace llarp struct LoggingConfig { - log::Type m_logType = log::Type::Unknown; + log::Type m_logType = log::Type::Print; log::Level m_logLevel = log::Level::off; std::string m_logFile; diff --git a/llarp/lokinet_shared.cpp b/llarp/lokinet_shared.cpp index 2452686ed..f2177d3de 100644 --- a/llarp/lokinet_shared.cpp +++ b/llarp/lokinet_shared.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef _WIN32 #define EHOSTDOWN ENETDOWN @@ -453,12 +454,17 @@ extern "C" int EXPORT lokinet_log_level(const char* level) { - if (auto maybe = llarp::log::level_from_string(level)) + try { - last_log_set = *maybe; - llarp::log::reset_level(*maybe); + auto new_level = llarp::log::level_from_string(level); + llarp::log::reset_level(new_level); + last_log_set = new_level; return 0; } + catch (std::invalid_argument& e) + { + llarp::LogError(e.what()); + } return -1; } diff --git a/test/util/test_llarp_util_log_level.cpp b/test/util/test_llarp_util_log_level.cpp index 7a67d9419..048c6324f 100644 --- a/test/util/test_llarp_util_log_level.cpp +++ b/test/util/test_llarp_util_log_level.cpp @@ -1,6 +1,7 @@ #include #include #include +#include using TestString = std::string; @@ -35,9 +36,16 @@ std::vector testParseLog{// bad cases TEST_CASE("parseLevel") { - const auto data = GENERATE(from_range(testParseLog)); - const auto maybe = llarp::log::level_from_string(data.input); - CHECK(maybe == data.level); + const auto& [input, expected] = GENERATE(from_range(testParseLog)); + + if (not expected) + REQUIRE_THROWS_AS(llarp::log::level_from_string(input), std::invalid_argument); + else + { + llarp::log::Level level; + REQUIRE_NOTHROW(level = llarp::log::level_from_string(input)); + CHECK(level == *expected); + } } TEST_CASE("TestLogLevelToString")