535{
536 std::string strValue;
537
538 auto const& itr = _configOptions.find(name);
539 bool notFound = itr == _configOptions.end();
540 auto envVarName = GetEnvVarName(name);
542 if (envVar)
543 {
544
545 if (showLogs && (notFound || itr->second != envVar->c_str()))
546 {
547 LOG_INFO(
"server.loading",
"> Config: Found config value '{}' from environment variable '{}'.", name, envVarName );
548 AddKey(name, envVar->c_str(), "ENVIRONMENT", false, false);
549 }
550
551 strValue = *envVar;
552 }
553 else if (notFound)
554 {
555 if (showLogs)
556 {
557 bool isCritical = _criticalConfigOptions.find(name) != _criticalConfigOptions.end();
558 ConfigSeverity severity = isCritical ? _policy.criticalOptionSeverity : _policy.missingOptionSeverity;
559
560 if (isCritical)
561 {
562 LogWithSeverity(severity, _filename,
563 "> 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!",
565 }
566 else
567 {
568 std::string configs = _filename;
570 configs += " or module config";
571
572 LogWithSeverity(severity, _filename,
573 "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
574 name, configs, name, def, envVarName);
575 }
576 }
577 return def;
578 }
579 else
580 {
581 strValue = itr->second;
582 }
583
584 auto value = Acore::StringTo<T>(strValue);
585 if (!value)
586 {
587 if (showLogs)
588 {
589 LogWithSeverity(_policy.valueErrorSeverity, _filename,
590 "> Config: Bad value defined for name '{}', going to use '{}' instead",
592 }
593
594 return def;
595 }
596
597 return *value;
598}
#define LOG_INFO(filterType__,...)
Definition Log.h:166
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
Optional< std::string > GetEnvFromCache(std::string const &configName, std::string const &envVarName)
Definition Config.cpp:489
ConfigSeverity
Definition Config.h:27
std::string ToString(Type &&val, Params &&... params)
Definition StringConvert.h:250