diff --git a/common/include/villas/log.hpp b/common/include/villas/log.hpp index 6ba1ce549..31600fc78 100644 --- a/common/include/villas/log.hpp +++ b/common/include/villas/log.hpp @@ -54,6 +54,8 @@ protected: Logger logger = logging.get("log"); DistSink sinks; + Level level; + std::string pattern; /**< Logging format. */ std::string prefix; /**< Prefix each line with this string. */ diff --git a/common/lib/log.cpp b/common/lib/log.cpp index e839dcf62..91985944e 100644 --- a/common/lib/log.cpp +++ b/common/lib/log.cpp @@ -35,16 +35,14 @@ using namespace villas; /** The global log instance */ Log villas::logging; -Log::Log(Level level) : - sinks(std::make_shared()), - pattern("%H:%M:%S %P %^%l%$: %v") +Log::Log(Level level) { char *p = getenv("VILLAS_LOG_PREFIX"); if (p) prefix = p; - spdlog::set_level(level); - spdlog::set_pattern(pattern, spdlog::pattern_time_type::utc); + setLevel(level); + setPattern("%H:%M:%S %^%l%$ %n: %v"); auto sink = std::make_shared(); @@ -143,6 +141,8 @@ void Log::setPattern(const std::string &pat) void Log::setLevel(Level lvl) { + level = lvl; + spdlog::set_level(lvl); } @@ -154,9 +154,7 @@ void Log::setLevel(const std::string &lvl) if (it == l.end()) throw RuntimeError("Invalid log level {}", lvl); - level = spdlog::level::from_str(lvl); - - setLevel(level); + setLevel(spdlog::level::from_str(lvl)); } Log::Level Log::getLevel() const