spdlog/include/spdlog/sinks/base_sink.h

47 lines
1.4 KiB
C
Raw Normal View History

2019-06-03 17:09:16 -04:00
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2016-04-20 04:57:49 -04:00
// 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.
2018-07-21 16:48:07 -04:00
// 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/sinks/sink.h"
2016-04-20 04:57:49 -04:00
2018-03-17 06:47:46 -04:00
namespace spdlog {
namespace sinks {
template<typename Mutex>
2018-03-16 11:35:56 -04:00
class base_sink : public sink
2016-04-20 04:57:49 -04:00
{
public:
base_sink();
explicit base_sink(std::unique_ptr<spdlog::formatter> formatter);
2018-03-09 08:26:33 -05:00
base_sink(const base_sink &) = delete;
base_sink &operator=(const base_sink &) = delete;
2019-05-08 10:50:23 -04:00
void log(const details::log_msg &msg) final;
2019-05-10 11:48:03 -04:00
void flush() final;
void set_pattern(const std::string &pattern) final;
2019-05-08 10:50:23 -04:00
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final;
2016-04-20 04:57:49 -04:00
protected:
// sink formatter
std::unique_ptr<spdlog::formatter> formatter_;
Mutex mutex_;
virtual void sink_it_(const details::log_msg &msg) = 0;
virtual void flush_() = 0;
2019-05-08 10:50:23 -04:00
virtual void set_pattern_(const std::string &pattern);
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter);
2016-04-20 04:57:49 -04:00
};
2018-03-17 06:47:46 -04:00
} // namespace sinks
} // namespace spdlog
2019-05-08 10:50:23 -04:00
2019-07-13 04:56:22 -04:00
#ifdef SPDLOG_HEADER_ONLY
2019-05-11 06:19:53 -04:00
#include "base_sink-inl.h"
#endif