1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-04-01 02:42:41 +08:00
spdlog/include/spdlog/sinks/base_sink.h

48 lines
1.4 KiB
C
Raw Normal View History

2019-06-04 05:09:16 +08:00
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2016-04-20 16:57:49 +08:00
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
//
2017-04-07 08:16:49 +08:00
// base sink templated over a mutex (either dummy or real)
// concrete implementation should override the sink_it_() and flush_() methods.
2018-07-22 04:48:07 +08:00
// locking is taken care of in this class - no locking needed by the
2023-09-29 03:58:50 +08:00
// implementers
2016-04-20 16:57:49 +08:00
//
2023-09-28 05:42:16 +08:00
#include "../common.h"
#include "../details/log_msg.h"
#include "sink.h"
2016-04-20 16:57:49 +08:00
2018-03-17 18:47:46 +08:00
namespace spdlog {
namespace sinks {
2023-09-25 07:35:55 +08:00
template <typename Mutex>
class SPDLOG_API base_sink : public sink {
2016-04-20 16:57:49 +08:00
public:
base_sink();
explicit base_sink(std::unique_ptr<spdlog::formatter> formatter);
2020-04-08 22:04:10 +08:00
~base_sink() override = default;
2018-03-09 21:26:33 +08:00
base_sink(const base_sink &) = delete;
2020-04-08 22:04:10 +08:00
base_sink(base_sink &&) = delete;
2018-03-09 21:26:33 +08:00
base_sink &operator=(const base_sink &) = delete;
2020-04-08 22:04:10 +08:00
base_sink &operator=(base_sink &&) = delete;
2019-05-08 22:50:23 +08:00
void log(const details::log_msg &msg) final;
2019-05-10 23:48:03 +08:00
void flush() final;
void set_pattern(const std::string &pattern) final;
2019-05-08 22:50:23 +08:00
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final;
2016-04-20 16:57:49 +08: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 22:50:23 +08:00
virtual void set_pattern_(const std::string &pattern);
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter);
2016-04-20 16:57:49 +08:00
};
2023-09-25 21:40:05 +08:00
} // namespace sinks
} // namespace spdlog