diff --git a/include/components/config.hpp b/include/components/config.hpp index 990d764f..c13ed1ca 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -245,7 +245,7 @@ class config { T result{convert(string{string_value})}; return dereference(string(section), move(key), move(string_value), move(result)); } catch (const key_error& err) { - throw value_error("Unexisting reference defined [" + section + "." + key + "]"); + throw value_error("Unexisting reference defined at [" + section + "." + key + "]"); } } @@ -266,16 +266,14 @@ class config { if (env_util::has(var.c_str())) { string env_value{env_util::get(var.c_str())}; - m_log.info("Found matching environment variable ${" + var + "} with the value \"" + env_value + "\""); + m_log.info("Environment var reference ${%s} found (value=%s)", var, env_value); return convert(move(env_value)); } else if (!env_default.empty()) { - m_log.info("The environment variable ${" + var + "} is undefined or empty, using defined fallback value \"" + - env_default + "\""); + m_log.info("Environment var ${%s} is undefined, using defined fallback value \"%s\"", var, env_default); + return convert(move(env_default)); } else { - m_log.info("The environment variable ${" + var + "} is undefined or empty"); + throw value_error(sstream() << "Environment var ${" << var << "} does not exist (no fallback set)"); } - - return convert(move(env_default)); } /** @@ -320,6 +318,7 @@ class config { /** * Dereference file reference by reading its contents * ${file:/absolute/file/path} + * ${file:/absolute/file/path:fallback value} */ template T dereference_file(string var) const { @@ -330,7 +329,15 @@ class config { var.erase(pos); } - return fallback; + if (file_util::exists(var)) { + m_log.info("File reference \"%s\" found", var); + return convert(string_util::trim(file_util::contents(var), '\n')); + } else if (!fallback.empty()) { + m_log.warn("File reference \"%s\" not found, using defined fallback value \"%s\"", var, fallback); + return convert(move(fallback)); + } else { + throw value_error(sstream() << "The file \"" << var << "\" does not exist (no fallback set)"); + } } private: diff --git a/src/components/config.cpp b/src/components/config.cpp index 99b58f64..b8ed8a12 100644 --- a/src/components/config.cpp +++ b/src/components/config.cpp @@ -43,7 +43,7 @@ config::config(const logger& logger, string&& path, string&& bar) throw application_error("Undefined bar: " + m_barname); } - m_log.trace("config: Loaded %s", m_file); + m_log.info("Loaded %s", m_file); m_log.trace("config: Current bar section: [%s]", section()); } diff --git a/src/components/logger.cpp b/src/components/logger.cpp index 3758b831..01da660a 100644 --- a/src/components/logger.cpp +++ b/src/components/logger.cpp @@ -26,7 +26,7 @@ size_t logger::convert(const std::thread::id arg) const { * Create instance */ logger::make_type logger::make(loglevel level) { - return static_cast(*factory_util::singleton>(level)); + return *factory_util::singleton>(level); } /**