diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index e48d27cd..8d4a47cc 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -30,7 +30,7 @@ public: base_sink(const base_sink &) = delete; base_sink &operator=(const base_sink &) = delete; - void log(const details::log_msg &msg) final + void log(const details::log_msg &msg) final override { std::lock_guard lock(mutex_); sink_it_(msg); @@ -45,18 +45,28 @@ public: void set_pattern(const std::string &pattern) final override { std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); + set_pattern_(pattern); } void set_formatter(std::unique_ptr sink_formatter) final override { std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); + set_formatter_(std::move(sink_formatter)); } protected: virtual void sink_it_(const details::log_msg &msg) = 0; virtual void flush_() = 0; + + virtual void set_pattern_(const std::string &pattern) + { + formatter_ = spdlog::make_unique(pattern); + } + + virtual void set_formatter_(std::unique_ptr sink_formatter) + { + formatter_ = std::move(sink_formatter); + } Mutex mutex_; }; } // namespace sinks