Commit b393715b authored by gabime's avatar gabime

Added virtual protected functions to base_sink

parent 5ec4e604
...@@ -30,7 +30,7 @@ public: ...@@ -30,7 +30,7 @@ public:
base_sink(const base_sink &) = delete; base_sink(const base_sink &) = delete;
base_sink &operator=(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<Mutex> lock(mutex_); std::lock_guard<Mutex> lock(mutex_);
sink_it_(msg); sink_it_(msg);
...@@ -45,18 +45,28 @@ public: ...@@ -45,18 +45,28 @@ public:
void set_pattern(const std::string &pattern) final override void set_pattern(const std::string &pattern) final override
{ {
std::lock_guard<Mutex> lock(mutex_); std::lock_guard<Mutex> lock(mutex_);
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern)); set_pattern_(pattern);
} }
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final override void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final override
{ {
std::lock_guard<Mutex> lock(mutex_); std::lock_guard<Mutex> lock(mutex_);
formatter_ = std::move(sink_formatter); set_formatter_(std::move(sink_formatter));
} }
protected: protected:
virtual void sink_it_(const details::log_msg &msg) = 0; virtual void sink_it_(const details::log_msg &msg) = 0;
virtual void flush_() = 0; virtual void flush_() = 0;
virtual void set_pattern_(const std::string &pattern)
{
formatter_ = spdlog::make_unique<spdlog::pattern_formatter>(pattern);
}
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)
{
formatter_ = std::move(sink_formatter);
}
Mutex mutex_; Mutex mutex_;
}; };
} // namespace sinks } // namespace sinks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment