602{
603 auto const& itr = _configOptions.find(name);
604 bool notFound = itr == _configOptions.end();
605 auto envVarName = GetEnvVarName(name);
607 if (envVar)
608 {
609
610 if (showLogs && (notFound || itr->second != envVar->c_str()))
611 {
612 LOG_INFO(
"server.loading",
"> Config: Found config value '{}' from environment variable '{}'.", name, envVarName);
613 AddKey(name, *envVar, "ENVIRONMENT", false, false);
614 }
615
616 return *envVar;
617 }
618 else if (notFound)
619 {
620 if (showLogs)
621 {
622 bool isCritical = _criticalConfigOptions.find(name) != _criticalConfigOptions.end();
623 ConfigSeverity severity = isCritical ? _policy.criticalOptionSeverity : _policy.missingOptionSeverity;
624
625 if (isCritical)
626 {
627 LogWithSeverity(severity, _filename,
628 "> 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!",
629 name, _filename, name, def, envVarName);
630 }
631 else
632 {
633 std::string configs = _filename;
634 if (!_moduleConfigFiles.empty())
635 configs += " or module config";
636
637 LogWithSeverity(severity, _filename,
638 "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
639 name, configs, name, def, envVarName);
640 }
641 }
642
643 return def;
644 }
645
646 return itr->second;
647}
#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