1// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3
4#pragma once
5//
6// base sink templated over a mutex (either dummy or real)
7// concrete implementation should override the sink_it_() and flush_() methods.
8// locking is taken care of in this class - no locking needed by the
9// implementers..
10//
11
12#include <spdlog/common.h>
13#include <spdlog/details/log_msg.h>
14#include <spdlog/sinks/sink.h>
15
16namespace spdlog {
17namespace sinks {
18template<typename Mutex>
19class SPDLOG_API base_sink : public sink
20{
21public:
22 base_sink();
23 explicit base_sink(std::unique_ptr<spdlog::formatter> formatter);
24 ~base_sink() override = default;
25
26 base_sink(const base_sink &) = delete;
27 base_sink(base_sink &&) = delete;
28
29 base_sink &operator=(const base_sink &) = delete;
30 base_sink &operator=(base_sink &&) = delete;
31
32 void log(const details::log_msg &msg) final;
33 void flush() final;
34 void set_pattern(const std::string &pattern) final;
35 void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final;
36
37protected:
38 // sink formatter
39 std::unique_ptr<spdlog::formatter> formatter_;
40 Mutex mutex_;
41
42 virtual void sink_it_(const details::log_msg &msg) = 0;
43 virtual void flush_() = 0;
44 virtual void set_pattern_(const std::string &pattern);
45 virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter);
46};
47} // namespace sinks
48} // namespace spdlog
49
50#ifdef SPDLOG_HEADER_ONLY
51# include "base_sink-inl.h"
52#endif
53