From 49f707ec932b07ef4a559e34231c9c48123dbf99 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 13 Dec 2019 01:24:34 +0200 Subject: [PATCH] wip --- include/spdlog/details/registry-inl.h | 23 +++++++++++++++++------ include/spdlog/details/registry.h | 6 +++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index 795fe062..987113c1 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -269,14 +269,25 @@ SPDLOG_INLINE void registry::set_configs(logger_cfgs configs) auto cfg_it = configs.loggers.find(logger->name()); // use default config if not found for this logger name - logger_cfg *cfg = cfg_it != configs.loggers.end() ? &cfg_it->second : &configs.default_cfg; - if(cfg->level_name.empty()) { - cfg->level_name = configs.default_cfg.level_name; + + logger_cfg *cfg; + if(cfg_it != configs.loggers.end()) + { + cfg = &cfg_it->second; + if(cfg->level_name.empty()) + { + cfg->level_name = configs.default_cfg.level_name; + } + if(cfg->level_name.empty()) + { + cfg->level_name = configs.default_cfg.level_name; + } + } + else + { + cfg = &configs.default_cfg; } - if(cfg->pattern.empty()) { - cfg->pattern = configs.default_cfg.pattern; - } logger->set_level(level::from_str(cfg->level_name)); logger->set_formatter(details::make_unique(cfg->pattern)); diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 8b81501c..82093534 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -29,14 +29,14 @@ class registry public: struct logger_cfg { - std::string level_name = "info"; - std::string pattern = "%+"; + std::string level_name; + std::string pattern; }; struct logger_cfgs { std::unordered_map loggers; - logger_cfg default_cfg; + logger_cfg default_cfg = {"info", "%+"}; }; registry(const registry &) = delete;