2019-06-04 05:09:16 +08:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2019-05-12 01:06:17 +08:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
2023-09-29 05:05:17 +08:00
|
|
|
#include "spdlog/common.h"
|
|
|
|
#include "spdlog/pattern_formatter.h"
|
|
|
|
#include "spdlog/sinks/base_sink.h"
|
2019-05-08 22:50:23 +08:00
|
|
|
|
2019-06-28 04:56:37 +08:00
|
|
|
#include <memory>
|
2023-09-25 01:26:32 +08:00
|
|
|
#include <mutex>
|
2019-06-28 04:56:37 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
2023-09-25 01:43:14 +08:00
|
|
|
spdlog::sinks::base_sink<Mutex>::base_sink()
|
2023-09-25 07:35:55 +08:00
|
|
|
: formatter_{std::make_unique<spdlog::pattern_formatter>()} {}
|
2019-06-28 04:56:37 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
2023-09-25 01:43:14 +08:00
|
|
|
spdlog::sinks::base_sink<Mutex>::base_sink(std::unique_ptr<spdlog::formatter> formatter)
|
2023-09-25 07:35:55 +08:00
|
|
|
: formatter_{std::move(formatter)} {}
|
2019-06-28 04:56:37 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
|
|
|
void spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg) {
|
2019-05-08 22:50:23 +08:00
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
sink_it_(msg);
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
|
|
|
void spdlog::sinks::base_sink<Mutex>::flush() {
|
2019-05-08 22:50:23 +08:00
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
flush_();
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern) {
|
2019-05-08 22:50:23 +08:00
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
set_pattern_(pattern);
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
2023-09-25 21:05:07 +08:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_formatter(
|
|
|
|
std::unique_ptr<spdlog::formatter> sink_formatter) {
|
2019-05-08 22:50:23 +08:00
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
set_formatter_(std::move(sink_formatter));
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern) {
|
2023-09-01 23:22:40 +08:00
|
|
|
set_formatter_(std::make_unique<spdlog::pattern_formatter>(pattern));
|
2019-05-08 22:50:23 +08:00
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
template <typename Mutex>
|
2023-09-25 21:05:07 +08:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_formatter_(
|
|
|
|
std::unique_ptr<spdlog::formatter> sink_formatter) {
|
2019-05-08 22:50:23 +08:00
|
|
|
formatter_ = std::move(sink_formatter);
|
|
|
|
}
|
2023-09-25 01:26:32 +08:00
|
|
|
|
|
|
|
// template instantiations
|
|
|
|
|
|
|
|
template class SPDLOG_API spdlog::sinks::base_sink<std::mutex>;
|
|
|
|
template class SPDLOG_API spdlog::sinks::base_sink<spdlog::details::null_mutex>;
|