From e83cc703d4d9b9d0832d4096f21b577a3dfc0624 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 15 Sep 2021 19:47:43 +0300 Subject: [PATCH] readded set_pattern impl --- include/spdlog/logger.h | 1 + include/spdlog/pattern_formatter-inl.h | 11 +++++++++++ include/spdlog/spdlog.h | 3 +++ 3 files changed, 15 insertions(+) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index e030c925..cbae9564 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -290,6 +290,7 @@ public: // set formatting for the sinks in this logger. // each sink will get a separate instance of the formatter object. void set_formatter(std::unique_ptr f); + void set_pattern(std::string pattern); // backtrace support. // efficiently store all debug/trace messages in a circular buffer until needed for debugging. diff --git a/include/spdlog/pattern_formatter-inl.h b/include/spdlog/pattern_formatter-inl.h index 118f7626..425a48a6 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -1287,4 +1288,14 @@ SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &patter formatters_.push_back(std::move(user_chars)); } } + +SPDLOG_INLINE void set_pattern(std::string pattern) +{ + set_formatter(details::make_unique(std::move(pattern))); +} + +SPDLOG_INLINE void logger::set_pattern(std::string pattern) +{ + this->set_formatter(details::make_unique(std::move(pattern))); +} } // namespace spdlog diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 818d73e5..4c769499 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -55,6 +55,9 @@ SPDLOG_API std::shared_ptr get(const std::string &name); // example: spdlog::set_formatter(std::make_unique("%Y-%m-%d %H:%M:%S.%e %l : %v")); SPDLOG_API void set_formatter(std::unique_ptr formatter); +// Set global log pattern. +SPDLOG_API void set_pattern(std::string pattern); + // enable global backtrace support SPDLOG_API void enable_backtrace(size_t n_messages);