Commit 0f2040e7 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

log: fix intialization of log level and pattern

parent 6dbb47ba
...@@ -54,6 +54,8 @@ protected: ...@@ -54,6 +54,8 @@ protected:
Logger logger = logging.get("log"); Logger logger = logging.get("log");
DistSink sinks; DistSink sinks;
Level level;
std::string pattern; /**< Logging format. */ std::string pattern; /**< Logging format. */
std::string prefix; /**< Prefix each line with this string. */ std::string prefix; /**< Prefix each line with this string. */
......
...@@ -35,16 +35,14 @@ using namespace villas; ...@@ -35,16 +35,14 @@ using namespace villas;
/** The global log instance */ /** The global log instance */
Log villas::logging; Log villas::logging;
Log::Log(Level level) : Log::Log(Level level)
sinks(std::make_shared<DistSink::element_type>()),
pattern("%H:%M:%S %P %^%l%$: %v")
{ {
char *p = getenv("VILLAS_LOG_PREFIX"); char *p = getenv("VILLAS_LOG_PREFIX");
if (p) if (p)
prefix = p; prefix = p;
spdlog::set_level(level); setLevel(level);
spdlog::set_pattern(pattern, spdlog::pattern_time_type::utc); setPattern("%H:%M:%S %^%l%$ %n: %v");
auto sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>(); auto sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
...@@ -143,6 +141,8 @@ void Log::setPattern(const std::string &pat) ...@@ -143,6 +141,8 @@ void Log::setPattern(const std::string &pat)
void Log::setLevel(Level lvl) void Log::setLevel(Level lvl)
{ {
level = lvl;
spdlog::set_level(lvl); spdlog::set_level(lvl);
} }
...@@ -154,9 +154,7 @@ void Log::setLevel(const std::string &lvl) ...@@ -154,9 +154,7 @@ void Log::setLevel(const std::string &lvl)
if (it == l.end()) if (it == l.end())
throw RuntimeError("Invalid log level {}", lvl); throw RuntimeError("Invalid log level {}", lvl);
level = spdlog::level::from_str(lvl); setLevel(spdlog::level::from_str(lvl));
setLevel(level);
} }
Log::Level Log::getLevel() const Log::Level Log::getLevel() const
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment