From dc166cad920d32a07e7db693876add8ba8a2d7ff Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 11 Nov 2018 01:18:57 +0200 Subject: [PATCH] Added default pattern support for pattern_formatter to avoid parsing pattern when using default pattern --- include/spdlog/details/pattern_formatter.h | 12 ++++++++++++ include/spdlog/details/registry.h | 2 +- include/spdlog/sinks/sink.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index b76bd485..38c28dfc 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -869,6 +869,18 @@ public: compile_pattern_(pattern_); } + // use by default full formatter for if pattern is not given + explicit pattern_formatter( + pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol) + : pattern_() + , eol_(std::move(eol)) + , pattern_time_type_(time_type) + , last_log_secs_(0) + { + std::memset(&cached_tm_, 0, sizeof(cached_tm_)); + formatters_.push_back(details::make_unique(details::padding_info())); + } + pattern_formatter(const pattern_formatter &other) = delete; pattern_formatter &operator=(const pattern_formatter &other) = delete; diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 439395f7..1f15b05e 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -231,7 +231,7 @@ public: private: registry() - : formatter_(new pattern_formatter("%+")) + : formatter_(new pattern_formatter()) { #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 9f84c378..2f1adc10 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -16,7 +16,7 @@ class sink public: sink() : level_(level::trace) - , formatter_(new pattern_formatter("%+")) + , formatter_(new pattern_formatter()) { }