2016-04-20 04:57:49 -04:00
|
|
|
//
|
|
|
|
// Copyright(c) 2015 Gabi Melman.
|
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
//
|
2017-04-06 20:16:49 -04:00
|
|
|
// base sink templated over a mutex (either dummy or real)
|
2018-07-07 05:12:45 -04:00
|
|
|
// concrete implementation should override the sink_it_() and flush_() methods.
|
|
|
|
// locking is taken care of in this class - no locking needed by the implementers..
|
2016-04-20 04:57:49 -04:00
|
|
|
//
|
|
|
|
|
2018-04-28 18:31:09 -04:00
|
|
|
#include "spdlog/common.h"
|
|
|
|
#include "spdlog/details/log_msg.h"
|
|
|
|
#include "spdlog/formatter.h"
|
|
|
|
#include "spdlog/sinks/sink.h"
|
2016-04-20 04:57:49 -04:00
|
|
|
|
2018-03-17 06:47:46 -04:00
|
|
|
namespace spdlog {
|
|
|
|
namespace sinks {
|
2018-03-16 11:35:56 -04:00
|
|
|
template<class Mutex>
|
|
|
|
class base_sink : public sink
|
2016-04-20 04:57:49 -04:00
|
|
|
{
|
|
|
|
public:
|
2018-06-23 18:32:39 -04:00
|
|
|
base_sink()
|
|
|
|
: sink()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-09 08:26:33 -05:00
|
|
|
base_sink(const base_sink &) = delete;
|
|
|
|
base_sink &operator=(const base_sink &) = delete;
|
2016-04-20 04:57:49 -04:00
|
|
|
|
2018-03-09 08:26:33 -05:00
|
|
|
void log(const details::log_msg &msg) SPDLOG_FINAL override
|
2016-04-20 04:57:49 -04:00
|
|
|
{
|
2018-06-10 15:59:17 -04:00
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
2018-06-23 18:32:39 -04:00
|
|
|
fmt::memory_buffer formatted;
|
|
|
|
formatter_->format(msg, formatted);
|
|
|
|
sink_it_(msg, formatted);
|
2016-04-20 04:57:49 -04:00
|
|
|
}
|
2018-02-24 17:56:56 -05:00
|
|
|
|
2017-06-29 03:51:44 -04:00
|
|
|
void flush() SPDLOG_FINAL override
|
|
|
|
{
|
2018-06-10 15:59:17 -04:00
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
flush_();
|
2017-06-29 03:51:44 -04:00
|
|
|
}
|
2016-04-20 04:57:49 -04:00
|
|
|
|
|
|
|
protected:
|
2018-06-23 18:32:39 -04:00
|
|
|
virtual void sink_it_(const details::log_msg &msg, const fmt::memory_buffer &formatted) = 0;
|
2018-06-10 15:59:17 -04:00
|
|
|
virtual void flush_() = 0;
|
|
|
|
Mutex mutex_;
|
2016-04-20 04:57:49 -04:00
|
|
|
};
|
2018-03-17 06:47:46 -04:00
|
|
|
} // namespace sinks
|
|
|
|
} // namespace spdlog
|