381{
382 std::string strValue;
383
385 bool fatalConfig = false;
389 if (envVar)
390 {
391
392 if (showLogs && (notFound || itr->second != envVar->c_str()))
393 {
394 LOG_INFO(
"server.loading",
"> Config: Found config value '{}' from environment variable '{}'.", name, envVarName );
395 AddKey(name, envVar->c_str(),
"ENVIRONMENT",
false,
false);
396 }
397
398 strValue = *envVar;
399 }
400 else if (notFound)
401 {
402 if (showLogs)
403 {
404 for (std::string s : _fatalConfigOptions)
405 if (s == name)
406 {
407 fatalConfig = true;
408 break;
409 }
410
411 if (fatalConfig)
412 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!",
414 else
415 LOG_WARN(
"server.loading",
"> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
417 }
418 return def;
419 }
420 else
421 {
422 strValue = itr->second;
423 }
424
425 auto value = Acore::StringTo<T>(strValue);
426 if (!value)
427 {
428 if (showLogs)
429 {
430 LOG_ERROR(
"server.loading",
"> Config: Bad value defined for name '{}', going to use '{}' instead",
432 }
433
434 return def;
435 }
436
437 return *value;
438}
#define LOG_FATAL(filterType__,...)
Definition: Log.h:152
#define LOG_INFO(filterType__,...)
Definition: Log.h:164
#define LOG_WARN(filterType__,...)
Definition: Log.h:160
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
std::string ToString(Type &&val, Params &&... params)
Definition: StringConvert.h:250
std::string GetEnvVarName(std::string const &configName)
Definition: Config.cpp:281
std::unordered_map< std::string, std::string > _configOptions
Definition: Config.cpp:34
void AddKey(std::string const &optionName, std::string const &optionKey, std::string_view fileName, bool isOptional, bool isReload)
Definition: Config.cpp:80
Optional< std::string > GetEnvFromCache(std::string const &configName, std::string const &envVarName)
Definition: Config.cpp:335