aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/config/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver/config/config.cpp')
-rw-r--r--src/zenserver/config/config.cpp73
1 files changed, 18 insertions, 55 deletions
diff --git a/src/zenserver/config/config.cpp b/src/zenserver/config/config.cpp
index 07913e891..2b77df642 100644
--- a/src/zenserver/config/config.cpp
+++ b/src/zenserver/config/config.cpp
@@ -16,8 +16,8 @@
#include <zencore/iobuffer.h>
#include <zencore/logging.h>
#include <zencore/string.h>
-#include <zenutil/commandlineoptions.h>
-#include <zenutil/environmentoptions.h>
+#include <zenutil/config/commandlineoptions.h>
+#include <zenutil/config/environmentoptions.h>
ZEN_THIRD_PARTY_INCLUDES_START
#include <fmt/format.h>
@@ -119,10 +119,17 @@ ZenServerConfiguratorBase::AddCommonConfigOptions(LuaConfig::Options& LuaOptions
ZenServerConfig& ServerOptions = m_ServerOptions;
+ // logging
+
+ LuaOptions.AddOption("server.logid"sv, ServerOptions.LoggingConfig.LogId, "log-id"sv);
+ LuaOptions.AddOption("server.abslog"sv, ServerOptions.LoggingConfig.AbsLogFile, "abslog"sv);
+ LuaOptions.AddOption("server.otlpendpoint"sv, ServerOptions.LoggingConfig.OtelEndpointUri, "otlp-endpoint"sv);
+ LuaOptions.AddOption("server.quiet"sv, ServerOptions.LoggingConfig.QuietConsole, "quiet"sv);
+ LuaOptions.AddOption("server.noconsole"sv, ServerOptions.LoggingConfig.NoConsoleOutput, "noconsole"sv);
+
// server
LuaOptions.AddOption("server.dedicated"sv, ServerOptions.IsDedicated, "dedicated"sv);
- LuaOptions.AddOption("server.logid"sv, ServerOptions.LogId, "log-id"sv);
LuaOptions.AddOption("server.sentry.disable"sv, ServerOptions.SentryConfig.Disable, "no-sentry"sv);
LuaOptions.AddOption("server.sentry.allowpersonalinfo"sv, ServerOptions.SentryConfig.AllowPII, "sentry-allow-personal-info"sv);
LuaOptions.AddOption("server.sentry.dsn"sv, ServerOptions.SentryConfig.Dsn, "sentry-dsn"sv);
@@ -131,12 +138,8 @@ ZenServerConfiguratorBase::AddCommonConfigOptions(LuaConfig::Options& LuaOptions
LuaOptions.AddOption("server.systemrootdir"sv, ServerOptions.SystemRootDir, "system-dir"sv);
LuaOptions.AddOption("server.datadir"sv, ServerOptions.DataDir, "data-dir"sv);
LuaOptions.AddOption("server.contentdir"sv, ServerOptions.ContentDir, "content-dir"sv);
- LuaOptions.AddOption("server.abslog"sv, ServerOptions.AbsLogFile, "abslog"sv);
- LuaOptions.AddOption("server.otlpendpoint"sv, ServerOptions.OtelEndpointUri, "otlp-endpoint"sv);
LuaOptions.AddOption("server.debug"sv, ServerOptions.IsDebug, "debug"sv);
LuaOptions.AddOption("server.clean"sv, ServerOptions.IsCleanStart, "clean"sv);
- LuaOptions.AddOption("server.quiet"sv, ServerOptions.QuietConsole, "quiet"sv);
- LuaOptions.AddOption("server.noconsole"sv, ServerOptions.NoConsoleOutput, "noconsole"sv);
////// network
@@ -182,9 +185,10 @@ struct ZenServerCmdLineOptions
std::string SystemRootDir;
std::string ContentDir;
std::string DataDir;
- std::string AbsLogFile;
std::string BaseSnapshotDir;
+ ZenLoggingCmdLineOptions LoggingOptions;
+
void AddCliOptions(cxxopts::Options& options, ZenServerConfig& ServerOptions);
void ApplyOptions(cxxopts::Options& options, ZenServerConfig& ServerOptions);
};
@@ -249,22 +253,7 @@ ZenServerCmdLineOptions::AddCliOptions(cxxopts::Options& options, ZenServerConfi
cxxopts::value<bool>(ServerOptions.ShouldCrash)->default_value("false"),
"");
- // clang-format off
- options.add_options("logging")
- ("abslog", "Path to log file", cxxopts::value<std::string>(AbsLogFile))
- ("log-id", "Specify id for adding context to log output", cxxopts::value<std::string>(ServerOptions.LogId))
- ("quiet", "Configure console logger output to level WARN", cxxopts::value<bool>(ServerOptions.QuietConsole)->default_value("false"))
- ("noconsole", "Disable console logging", cxxopts::value<bool>(ServerOptions.NoConsoleOutput)->default_value("false"))
- ("log-trace", "Change selected loggers to level TRACE", cxxopts::value<std::string>(ServerOptions.Loggers[logging::level::Trace]))
- ("log-debug", "Change selected loggers to level DEBUG", cxxopts::value<std::string>(ServerOptions.Loggers[logging::level::Debug]))
- ("log-info", "Change selected loggers to level INFO", cxxopts::value<std::string>(ServerOptions.Loggers[logging::level::Info]))
- ("log-warn", "Change selected loggers to level WARN", cxxopts::value<std::string>(ServerOptions.Loggers[logging::level::Warn]))
- ("log-error", "Change selected loggers to level ERROR", cxxopts::value<std::string>(ServerOptions.Loggers[logging::level::Err]))
- ("log-critical", "Change selected loggers to level CRITICAL", cxxopts::value<std::string>(ServerOptions.Loggers[logging::level::Critical]))
- ("log-off", "Change selected loggers to level OFF", cxxopts::value<std::string>(ServerOptions.Loggers[logging::level::Off]))
- ("otlp-endpoint", "OpenTelemetry endpoint URI (e.g http://localhost:4318)", cxxopts::value<std::string>(ServerOptions.OtelEndpointUri))
- ;
- // clang-format on
+ LoggingOptions.AddCliOptions(options, ServerOptions.LoggingConfig);
options
.add_option("lifetime", "", "owner-pid", "Specify owning process id", cxxopts::value<int>(ServerOptions.OwnerPid), "<identifier>");
@@ -394,9 +383,10 @@ ZenServerCmdLineOptions::ApplyOptions(cxxopts::Options& options, ZenServerConfig
ServerOptions.SystemRootDir = MakeSafeAbsolutePath(SystemRootDir);
ServerOptions.DataDir = MakeSafeAbsolutePath(DataDir);
ServerOptions.ContentDir = MakeSafeAbsolutePath(ContentDir);
- ServerOptions.AbsLogFile = MakeSafeAbsolutePath(AbsLogFile);
ServerOptions.ConfigFile = MakeSafeAbsolutePath(ConfigFile);
ServerOptions.BaseSnapshotDir = MakeSafeAbsolutePath(BaseSnapshotDir);
+
+ LoggingOptions.ApplyOptions(ServerOptions.LoggingConfig);
}
//////////////////////////////////////////////////////////////////////////
@@ -466,34 +456,7 @@ ZenServerConfiguratorBase::Configure(int argc, char* argv[])
}
#endif
- if (m_ServerOptions.QuietConsole)
- {
- bool HasExplicitConsoleLevel = false;
- for (int i = 0; i < logging::level::LogLevelCount; ++i)
- {
- if (m_ServerOptions.Loggers[i].find("console") != std::string::npos)
- {
- HasExplicitConsoleLevel = true;
- break;
- }
- }
-
- if (!HasExplicitConsoleLevel)
- {
- std::string& WarnLoggers = m_ServerOptions.Loggers[logging::level::Warn];
- if (!WarnLoggers.empty())
- {
- WarnLoggers += ",";
- }
- WarnLoggers += "console";
- }
- }
-
- for (int i = 0; i < logging::level::LogLevelCount; ++i)
- {
- logging::ConfigureLogLevels(logging::level::LogLevel(i), m_ServerOptions.Loggers[i]);
- }
- logging::RefreshLogLevels();
+ ApplyLoggingOptions(options, m_ServerOptions.LoggingConfig);
BaseOptions.ApplyOptions(options, m_ServerOptions);
ApplyOptions(options);
@@ -532,9 +495,9 @@ ZenServerConfiguratorBase::Configure(int argc, char* argv[])
m_ServerOptions.DataDir = PickDefaultStateDirectory(m_ServerOptions.SystemRootDir);
}
- if (m_ServerOptions.AbsLogFile.empty())
+ if (m_ServerOptions.LoggingConfig.AbsLogFile.empty())
{
- m_ServerOptions.AbsLogFile = m_ServerOptions.DataDir / "logs" / "zenserver.log";
+ m_ServerOptions.LoggingConfig.AbsLogFile = m_ServerOptions.DataDir / "logs" / "zenserver.log";
}
m_ServerOptions.HttpConfig.IsDedicatedServer = m_ServerOptions.IsDedicated;