aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-08-26 14:05:15 +0200
committerGitHub Enterprise <[email protected]>2025-08-26 14:05:15 +0200
commit0cc32cae5e3fb832bbad584ce86a308dc6104c46 (patch)
tree33d81192d767864b5149aeece975b321ef04a00a /src
parentimprove console output (#476) (diff)
downloadzen-0cc32cae5e3fb832bbad584ce86a308dc6104c46.tar.xz
zen-0cc32cae5e3fb832bbad584ce86a308dc6104c46.zip
rework `--quiet` zenserver option add `--noconsole` option (#477)
- Improvement: Changed zenserver `--quiet` option to suppress INFO level messages and below to surface startup and runtime errors - Feature: Added `--noconsole` option that suppresses all output to standard out, this works as the `--quiet` option used to work
Diffstat (limited to 'src')
-rw-r--r--src/zenserver/config.cpp47
-rw-r--r--src/zenserver/config.h1
-rw-r--r--src/zenserver/diag/logging.cpp1
-rw-r--r--src/zenserver/main.cpp57
-rw-r--r--src/zenserver/zenserver.cpp19
-rw-r--r--src/zenutil/include/zenutil/logging.h1
-rw-r--r--src/zenutil/logging.cpp4
7 files changed, 92 insertions, 38 deletions
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp
index 392ca4aaa..fb2d9b7f4 100644
--- a/src/zenserver/config.cpp
+++ b/src/zenserver/config.cpp
@@ -482,7 +482,8 @@ ParseConfigFile(const std::filesystem::path& Path,
LuaOptions.AddOption("server.pluginsconfigfile"sv, ServerOptions.PluginsConfigFile, "plugins-config"sv);
LuaOptions.AddOption("server.debug"sv, ServerOptions.IsDebug, "debug"sv);
LuaOptions.AddOption("server.clean"sv, ServerOptions.IsCleanStart, "clean"sv);
- LuaOptions.AddOption("server.noconsole"sv, ServerOptions.NoConsoleOutput, "quiet"sv);
+ LuaOptions.AddOption("server.quiet"sv, ServerOptions.QuietConsole, "quiet"sv);
+ LuaOptions.AddOption("server.noconsole"sv, ServerOptions.NoConsoleOutput, "noconsole"sv);
////// objectstore
LuaOptions.AddOption("server.objectstore.enabled"sv, ServerOptions.ObjectStoreEnabled, "objectstore-enabled"sv);
@@ -812,16 +813,17 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
// 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", "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]))
+ ("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]))
;
// clang-format on
@@ -1356,6 +1358,29 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
ZEN_TRACE_CPU("ConfigParse");
+ if (ServerOptions.QuietConsole)
+ {
+ bool HasExplicitConsoleLevel = false;
+ for (int i = 0; i < logging::level::LogLevelCount; ++i)
+ {
+ if (ServerOptions.Loggers[i].find("console") != std::string::npos)
+ {
+ HasExplicitConsoleLevel = true;
+ break;
+ }
+ }
+
+ if (!HasExplicitConsoleLevel)
+ {
+ std::string& WarnLoggers = 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), ServerOptions.Loggers[i]);
diff --git a/src/zenserver/config.h b/src/zenserver/config.h
index 9e8787957..8380e72e7 100644
--- a/src/zenserver/config.h
+++ b/src/zenserver/config.h
@@ -206,6 +206,7 @@ struct ZenServerOptions
bool Detach = true; // Whether zenserver should detach from existing process group (Mac/Linux)
bool ObjectStoreEnabled = false;
bool NoConsoleOutput = false; // Control default use of stdout for diagnostics
+ bool QuietConsole = false; // Configure console logger output to level WARN
std::string Loggers[zen::logging::level::LogLevelCount];
std::string ScrubOptions;
#if ZEN_WITH_TRACE
diff --git a/src/zenserver/diag/logging.cpp b/src/zenserver/diag/logging.cpp
index f3d3377b0..34d9b05b7 100644
--- a/src/zenserver/diag/logging.cpp
+++ b/src/zenserver/diag/logging.cpp
@@ -27,6 +27,7 @@ InitializeServerLogging(const ZenServerOptions& InOptions)
.IsVerbose = false,
.IsTest = InOptions.IsTest,
.NoConsoleOutput = InOptions.NoConsoleOutput,
+ .QuietConsole = InOptions.QuietConsole,
.AbsLogFile = InOptions.AbsLogFile,
.LogId = InOptions.LogId};
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp
index f7d69617c..d512d4894 100644
--- a/src/zenserver/main.cpp
+++ b/src/zenserver/main.cpp
@@ -139,21 +139,23 @@ ZenEntryPoint::Run()
{
if (Ec)
{
- ZEN_WARN(
- "Sponsor owner pid {} can not be checked for running state, reason: '{}'. Will not add sponsor to process "
- "listening to port {} (pid: {})",
- m_ServerOptions.OwnerPid,
- Ec.message(),
- m_ServerOptions.BasePort,
- Entry->Pid.load());
+ ZEN_WARN(ZEN_APP_NAME
+ " exiting, sponsor owner pid {} can not be checked for running state, reason: '{}'. Will not add sponsor "
+ "to process "
+ "listening to port {} (pid: {})",
+ m_ServerOptions.OwnerPid,
+ Ec.message(),
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
}
else
{
- ZEN_WARN(
- "Sponsor owner pid {} is no longer running, will not add sponsor to process listening to port {} (pid: {})",
- m_ServerOptions.OwnerPid,
- m_ServerOptions.BasePort,
- Entry->Pid.load());
+ ZEN_WARN(ZEN_APP_NAME
+ " exiting, sponsor owner pid {} is no longer running, will not add sponsor to process listening to port "
+ "{} (pid: {})",
+ m_ServerOptions.OwnerPid,
+ m_ServerOptions.BasePort,
+ Entry->Pid.load());
}
std::exit(1);
}
@@ -175,7 +177,7 @@ ZenEntryPoint::Run()
}
else
{
- ZEN_WARN("Failed to add sponsor owner pid {} to process listening to port {} (pid: {})",
+ ZEN_WARN(ZEN_APP_NAME " exiting, failed to add sponsor owner pid {} to process listening to port {} (pid: {})",
m_ServerOptions.OwnerPid,
m_ServerOptions.BasePort,
Entry->Pid.load());
@@ -184,7 +186,7 @@ ZenEntryPoint::Run()
}
else
{
- ZEN_WARN("Exiting since there is already a process listening to port {} (pid: {})",
+ ZEN_WARN(ZEN_APP_NAME " exiting, there is already a process listening to port {} (pid: {})",
m_ServerOptions.BasePort,
Entry->Pid.load());
std::exit(1);
@@ -208,14 +210,19 @@ ZenEntryPoint::Run()
if (Ec)
{
- ZEN_WARN("Unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message());
- Sleep(500);
+ ZEN_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message());
+ Sleep(100);
m_LockFile.Create(LockFilePath, MakeLockData(false), Ec);
if (Ec)
{
- ZEN_WARN("ERROR: Unable to grab lock at '{}' (reason: '{}')", LockFilePath, Ec.message());
- std::exit(99);
+ ZEN_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message());
+ Sleep(500);
+ if (Ec)
+ {
+ ZEN_WARN(ZEN_APP_NAME " exiting, unable to grab lock at '{}' (reason: '{}')", LockFilePath, Ec.message());
+ std::exit(99);
+ }
}
}
@@ -316,12 +323,14 @@ ZenEntryPoint::Run()
}
catch (const AssertException& AssertEx)
{
- ZEN_CRITICAL("Caught assert exception in main for process {}: {}", zen::GetCurrentProcessId(), AssertEx.FullDescription());
+ ZEN_CRITICAL(ZEN_APP_NAME " caught assert exception in main for process {}: {}",
+ zen::GetCurrentProcessId(),
+ AssertEx.FullDescription());
RequestApplicationExit(1);
}
catch (const std::system_error& e)
{
- ZEN_CRITICAL("Caught system error exception in main for process {}: {} ({})",
+ ZEN_CRITICAL(ZEN_APP_NAME " caught system error exception in main for process {}: {} ({})",
zen::GetCurrentProcessId(),
e.what(),
e.code().value());
@@ -329,7 +338,7 @@ ZenEntryPoint::Run()
}
catch (const std::exception& e)
{
- ZEN_CRITICAL("Caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what());
+ ZEN_CRITICAL(ZEN_APP_NAME " caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what());
RequestApplicationExit(1);
}
@@ -499,17 +508,17 @@ main(int argc, char* argv[])
catch (const OptionParseException& ParseEx)
{
// The parsing error already outputs all the details so no need to output the command line here
- fprintf(stderr, "ERROR: %s\n", ParseEx.what());
+ fprintf(stderr, ZEN_APP_NAME " ERROR: %s\n", ParseEx.what());
return 1;
}
catch (const AssertException& AssertEx)
{
- fprintf(stderr, "ERROR: Caught assert exception in main: '%s'", AssertEx.FullDescription().c_str());
+ fprintf(stderr, ZEN_APP_NAME " ERROR: Caught assert exception in main: '%s'", AssertEx.FullDescription().c_str());
return 1;
}
catch (const std::exception& Ex)
{
- fprintf(stderr, "ERROR: Caught exception in main: '%s'", Ex.what());
+ fprintf(stderr, ZEN_APP_NAME " ERROR: Caught exception in main: '%s'", Ex.what());
return 1;
}
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 48a2dad95..44c25368c 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -187,7 +187,14 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen
m_Http = CreateHttpServer(ServerOptions.HttpServerConfig);
int EffectiveBasePort = m_Http->Initialize(ServerOptions.BasePort, ServerOptions.DataDir);
- ZEN_ASSERT(EffectiveBasePort > 0);
+ if (EffectiveBasePort == 0)
+ {
+ ZEN_WARN("Failed to initialize http service '{}' using base port {} and data dir {}",
+ ServerOptions.HttpServerConfig.ServerClass,
+ ServerOptions.BasePort,
+ ServerOptions.DataDir);
+ return -1;
+ }
// Setup authentication manager
{
@@ -198,7 +205,10 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen
{
EncryptionKey = "abcdefghijklmnopqrstuvxyz0123456";
- ZEN_WARN("using default encryption key");
+ if (ServerOptions.IsDedicated)
+ {
+ ZEN_WARN("Using default encryption key for authentication state");
+ }
}
std::string EncryptionIV = ServerOptions.EncryptionIV;
@@ -207,7 +217,10 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen
{
EncryptionIV = "0123456789abcdef";
- ZEN_WARN("using default encryption initialization vector");
+ if (ServerOptions.IsDedicated)
+ {
+ ZEN_WARN("Using default encryption initialization vector for authentication state");
+ }
}
m_AuthMgr = AuthMgr::Create({.RootDirectory = m_DataRoot / "auth",
diff --git a/src/zenutil/include/zenutil/logging.h b/src/zenutil/include/zenutil/logging.h
index d64eef207..85ddc86cd 100644
--- a/src/zenutil/include/zenutil/logging.h
+++ b/src/zenutil/include/zenutil/logging.h
@@ -34,6 +34,7 @@ struct LoggingOptions
bool IsTest = false;
bool AllowAsync = true;
bool NoConsoleOutput = false;
+ bool QuietConsole = false;
std::filesystem::path AbsLogFile; // Absolute path to main log file
std::string LogId;
};
diff --git a/src/zenutil/logging.cpp b/src/zenutil/logging.cpp
index cb0fd6679..8ff58ee73 100644
--- a/src/zenutil/logging.cpp
+++ b/src/zenutil/logging.cpp
@@ -121,6 +121,10 @@ BeginInitializeLogging(const LoggingOptions& LogOptions)
else
{
auto ConsoleSink = std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>();
+ if (LogOptions.QuietConsole)
+ {
+ ConsoleSink->set_level(spdlog::level::warn);
+ }
Sinks.push_back(ConsoleSink);
}