Files
spdlog/include/spdlog/sinks/base_sink.h

63 lines
1.5 KiB
C
Raw Normal View History

2016-04-20 11:57:49 +03: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)
// 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 11:57:49 +03:00
//
2018-04-29 01:31:09 +03:00
#include "spdlog/common.h"
#include "spdlog/details/log_msg.h"
#include "spdlog/formatter.h"
#include "spdlog/sinks/sink.h"
2016-04-20 11:57:49 +03:00
2018-03-17 12:47:46 +02:00
namespace spdlog {
namespace sinks {
template<typename Mutex>
2018-03-16 17:35:56 +02:00
class base_sink : public sink
2016-04-20 11:57:49 +03:00
{
public:
2018-06-24 01:32:39 +03:00
base_sink()
: sink()
{
}
2018-03-09 15:26:33 +02:00
base_sink(const base_sink &) = delete;
base_sink &operator=(const base_sink &) = delete;
2016-04-20 11:57:49 +03:00
2018-03-09 15:26:33 +02:00
void log(const details::log_msg &msg) SPDLOG_FINAL override
2016-04-20 11:57:49 +03:00
{
std::lock_guard<Mutex> lock(mutex_);
sink_it_(msg);
2016-04-20 11:57:49 +03:00
}
2018-02-24 23:56:56 +01:00
void flush() SPDLOG_FINAL override
{
std::lock_guard<Mutex> lock(mutex_);
flush_();
}
2016-04-20 11:57:49 +03:00
void set_pattern(const std::string &pattern) SPDLOG_FINAL override
{
std::lock_guard<Mutex> lock(mutex_);
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
}
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) SPDLOG_FINAL override
{
std::lock_guard<Mutex> lock(mutex_);
formatter_ = std::move(sink_formatter);
}
2016-04-20 11:57:49 +03:00
protected:
virtual void sink_it_(const details::log_msg &msg) = 0;
virtual void flush_() = 0;
Mutex mutex_;
2016-04-20 11:57:49 +03:00
};
2018-03-17 12:47:46 +02:00
} // namespace sinks
} // namespace spdlog