From 6031ae2eb918ee21b3bc3da78bbb20bdc80ecd71 Mon Sep 17 00:00:00 2001
From: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
Date: Thu, 4 Jul 2024 19:25:28 +0200
Subject: chore(Core/Conf): Show better logging when fatal config options are
m… (#19236)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
chore(Core/Conf): Show better logging when fatal config options are missing
* Show better log when the server halts due to missing fatal config option
* Change error to warning for missing config options. As they are not errors
* Update output when autoupdater is disabled for all databases
---
src/common/Configuration/Config.cpp | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
(limited to 'src/common')
diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp
index 742777b186..d8665593ca 100644
--- a/src/common/Configuration/Config.cpp
+++ b/src/common/Configuration/Config.cpp
@@ -35,6 +35,14 @@ namespace
std::unordered_map _envVarCache;
std::mutex _configLock;
+ std::vector _fatalConfigOptions =
+ {
+ { "RealmID" },
+ { "LoginDatabaseInfo" },
+ { "WorldDatabaseInfo" },
+ { "CharacterDatabaseInfo" },
+ };
+
// Check system configs like *server.conf*
bool IsAppConfig(std::string_view fileName)
{
@@ -388,6 +396,7 @@ T ConfigMgr::GetValueDefault(std::string const& name, T const& def, bool showLog
std::string strValue;
auto const& itr = _configOptions.find(name);
+ bool fatalConfig = false;
bool notFound = itr == _configOptions.end();
auto envVarName = GetEnvVarName(name);
Optional envVar = GetEnvFromCache(name, envVarName);
@@ -406,7 +415,18 @@ T ConfigMgr::GetValueDefault(std::string const& name, T const& def, bool showLog
{
if (showLogs)
{
- LOG_ERROR("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
+ for (std::string s : _fatalConfigOptions)
+ if (s == name)
+ {
+ fatalConfig = true;
+ break;
+ }
+
+ if (fatalConfig)
+ LOG_FATAL("server.loading", "> Config:\n\nFATAL ERROR: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable\n\nYour server cannot start without this option!",
+ name, _filename, name, Acore::ToString(def), envVarName);
+ else
+ LOG_WARN("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
name, _filename, name, Acore::ToString(def), envVarName);
}
return def;
@@ -435,6 +455,7 @@ template<>
std::string ConfigMgr::GetValueDefault(std::string const& name, std::string const& def, bool showLogs /*= true*/) const
{
auto const& itr = _configOptions.find(name);
+ bool fatalConfig = false;
bool notFound = itr == _configOptions.end();
auto envVarName = GetEnvVarName(name);
Optional envVar = GetEnvFromCache(name, envVarName);
@@ -453,7 +474,18 @@ std::string ConfigMgr::GetValueDefault(std::string const& name, std
{
if (showLogs)
{
- LOG_ERROR("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
+ for (std::string s : _fatalConfigOptions)
+ if (s == name)
+ {
+ fatalConfig = true;
+ break;
+ }
+
+ if (fatalConfig)
+ LOG_FATAL("server.loading", "> Config:\n\nFATAL ERROR: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.\n\nYour server cannot start without this option!",
+ name, _filename, name, def, envVarName);
+ else
+ LOG_WARN("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
name, _filename, name, def, envVarName);
}
--
cgit v1.2.3