From f51cda8b7de0f5ac6fa0aa8f624316b51531761a Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Thu, 20 Jun 2024 20:18:31 +0000 Subject: [PATCH] Process plog severity correctly from CLI11 flag. --- .../server/NetRemoteServerConfiguration.cxx | 7 +++--- .../service/NetRemoteServerConfiguration.hxx | 24 +++++++++++++++---- src/common/shared/logging/LogUtils.cxx | 10 +++++--- src/linux/server/Main.cxx | 3 ++- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/common/server/NetRemoteServerConfiguration.cxx b/src/common/server/NetRemoteServerConfiguration.cxx index e1aa1d7c..b438da04 100644 --- a/src/common/server/NetRemoteServerConfiguration.cxx +++ b/src/common/server/NetRemoteServerConfiguration.cxx @@ -27,9 +27,10 @@ ConfigureCliAppOptions(CLI::App& app, NetRemoteServerConfiguration& config) "The address to listen on for incoming connections"); app.add_flag( - "-v,--verbosity", - config.LogVerbosity, - "The log verbosity level. Supply multiple times to increase verbosity (0=warnings, errors, and fatal messages, 1=info messages, 2=debug messages, 3=verbose messages)"); + "-v,--verbosity", + config.LogVerbosity, + "The log verbosity level. Supply multiple times to increase verbosity (0=fatal, 1=errors, 2=warnings, 3=info, 4=debug, 5+=verbose)") + ->default_val(NetRemoteServerConfiguration::LogVerbosityDefault); app.add_flag( "--enable-file-logging", diff --git a/src/common/server/include/microsoft/net/remote/service/NetRemoteServerConfiguration.hxx b/src/common/server/include/microsoft/net/remote/service/NetRemoteServerConfiguration.hxx index 79f4ef33..8c8c3b68 100644 --- a/src/common/server/include/microsoft/net/remote/service/NetRemoteServerConfiguration.hxx +++ b/src/common/server/include/microsoft/net/remote/service/NetRemoteServerConfiguration.hxx @@ -18,6 +18,11 @@ namespace Microsoft::Net::Remote::Service */ struct NetRemoteServerConfiguration { + /** + * @brief Default log verbosity. + */ + static constexpr auto LogVerbosityDefault = 3; + /** * @brief Create a NetRemoteServerConfiguration object from command-line * arguments. @@ -52,12 +57,21 @@ struct NetRemoteServerConfiguration bool RunInBackground{ false }; /** - * @brief How verbose log output should be. The default level is 0, which - * will show all warnings, errors, and fatal messages. A level of 1 will - * show all info messages, and a level of 2 will show all debug messages, - * and a level of 3 or above will show all verbose messages. + * @brief Log verbosity threshold. The default level is 'info' (3) which will print all log messages with verbosity + * level info, warning, error, and fatal. + * + * -------------------- + * | level | severity | + * | ----- | -------- | + * | 0 | fatal | + * | 1 | error | + * | 2 | warning | + * | 3 | info | + * | 4 | debug | + * | 5+ | verbose | + * -------------------- */ - uint32_t LogVerbosity{ 0 }; + uint32_t LogVerbosity{ LogVerbosityDefault }; /** * @brief Whether to enable logging to file or not. diff --git a/src/common/shared/logging/LogUtils.cxx b/src/common/shared/logging/LogUtils.cxx index 9c0dd5e5..e810e65b 100644 --- a/src/common/shared/logging/LogUtils.cxx +++ b/src/common/shared/logging/LogUtils.cxx @@ -31,12 +31,16 @@ logging::LogVerbosityToPlogSeverity(uint32_t verbosity) noexcept { switch (verbosity) { case 0: - return plog::warning; + return plog::fatal; case 1: - return plog::info; + return plog::error; case 2: - return plog::debug; + return plog::warning; case 3: + return plog::info; + case 4: + return plog::debug; + case 5: default: return plog::verbose; } diff --git a/src/linux/server/Main.cxx b/src/linux/server/Main.cxx index 8bf27c90..8be5ae01 100644 --- a/src/linux/server/Main.cxx +++ b/src/linux/server/Main.cxx @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -125,7 +126,7 @@ main(int argc, char *argv[]) NetRemoteServer server{ configuration }; // Start the server. - LOGI << "Netremote server starting"; + LOGN << std::format("Netremote server starting (log level={})", magic_enum::enum_name(logSeverity)); server.Run(); // If running in the background, daemonize the process.