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)
|
|
|
|
|
|
|
|
|
2019-05-13 05:09:00 +08:00
|
|
|
|
2023-09-25 01:26:32 +08:00
|
|
|
#include <spdlog/sinks/base_sink.h>
|
2019-11-07 03:09:30 +08:00
|
|
|
#include <spdlog/common.h>
|
2020-03-21 19:33:04 +08:00
|
|
|
#include <spdlog/pattern_formatter.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
|
|
|
|
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +08:00
|
|
|
spdlog::sinks::base_sink<Mutex>::base_sink()
|
2023-09-01 23:22:40 +08:00
|
|
|
: formatter_{std::make_unique<spdlog::pattern_formatter>()}
|
2019-06-28 04:56:37 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +08:00
|
|
|
spdlog::sinks::base_sink<Mutex>::base_sink(std::unique_ptr<spdlog::formatter> formatter)
|
2019-06-28 04:56:37 +08:00
|
|
|
: formatter_{std::move(formatter)}
|
|
|
|
{}
|
|
|
|
|
2019-05-10 23:48:03 +08:00
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-10 23:48:03 +08:00
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +08:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::flush()
|
2019-05-08 22:50:23 +08:00
|
|
|
{
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
flush_();
|
|
|
|
}
|
|
|
|
|
2019-05-10 23:48:03 +08:00
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-10 23:48:03 +08:00
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +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));
|
|
|
|
}
|
|
|
|
|
2019-05-10 23:48:03 +08:00
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +08:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
|
2019-05-08 22:50:23 +08:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2019-05-10 23:48:03 +08:00
|
|
|
template<typename Mutex>
|
2023-09-24 18:02:30 +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>;
|