Added virtual protected functions to base_sink

This commit is contained in:
gabime 2018-09-26 15:27:48 +03:00
parent 5ec4e60424
commit b393715bee

View File

@ -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<Mutex> lock(mutex_);
sink_it_(msg);
@ -45,18 +45,28 @@ public:
void set_pattern(const std::string &pattern) final override
{
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
{
std::lock_guard<Mutex> 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<spdlog::pattern_formatter>(pattern);
}
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)
{
formatter_ = std::move(sink_formatter);
}
Mutex mutex_;
};
} // namespace sinks