1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-03-06 22:25:47 +08:00
spdlog/src/sinks/base_sink.cpp

59 lines
1.8 KiB
C++
Raw Normal View History

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)
#include "spdlog/sinks/base_sink.h"
2019-05-08 22:50:23 +08:00
#include <memory>
2023-09-25 01:26:32 +08:00
#include <mutex>
2023-09-29 05:20:26 +08:00
#include "spdlog/common.h"
#include "spdlog/pattern_formatter.h"
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>()} {}
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)} {}
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>
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) {
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>
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>;