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)
|
2018-07-07 17:12:45 +08:00
|
|
|
// 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:
|
2019-06-28 04:56:37 +08:00
|
|
|
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;
|
2018-07-14 21:21:53 +08:00
|
|
|
|
2016-04-20 16:57:49 +08:00
|
|
|
protected:
|
2019-06-28 04:56:37 +08:00
|
|
|
// sink formatter
|
|
|
|
std::unique_ptr<spdlog::formatter> formatter_;
|
2021-10-16 23:52:01 +08:00
|
|
|
Mutex mutex_;
|
2019-06-28 04:56:37 +08:00
|
|
|
|
2018-07-14 21:21:53 +08:00
|
|
|
virtual void sink_it_(const details::log_msg &msg) = 0;
|
2018-06-11 03:59:17 +08:00
|
|
|
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
|