2019-06-04 00:09:16 +03:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2019-05-11 20:06:17 +03:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
|
|
|
|
|
|
2019-05-13 00:09:00 +03:00
|
|
|
|
2023-09-24 20:26:32 +03:00
|
|
|
#include <spdlog/sinks/base_sink.h>
|
2019-11-06 19:09:30 +00:00
|
|
|
#include <spdlog/common.h>
|
2020-03-21 13:33:04 +02:00
|
|
|
#include <spdlog/pattern_formatter.h>
|
2019-05-08 17:50:23 +03:00
|
|
|
|
2019-06-27 23:56:37 +03:00
|
|
|
#include <memory>
|
2023-09-24 20:26:32 +03:00
|
|
|
#include <mutex>
|
2019-06-27 23:56:37 +03:00
|
|
|
|
|
|
|
|
template<typename Mutex>
|
2023-09-24 13:02:30 +03:00
|
|
|
spdlog::sinks::base_sink<Mutex>::base_sink()
|
2023-09-01 18:22:40 +03:00
|
|
|
: formatter_{std::make_unique<spdlog::pattern_formatter>()}
|
2019-06-27 23:56:37 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
template<typename Mutex>
|
2023-09-24 13:02:30 +03:00
|
|
|
spdlog::sinks::base_sink<Mutex>::base_sink(std::unique_ptr<spdlog::formatter> formatter)
|
2019-06-27 23:56:37 +03:00
|
|
|
: formatter_{std::move(formatter)}
|
|
|
|
|
{}
|
|
|
|
|
|
2019-05-10 18:48:03 +03:00
|
|
|
template<typename Mutex>
|
2023-09-24 13:02:30 +03:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg)
|
2019-05-08 17:50:23 +03:00
|
|
|
{
|
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
|
sink_it_(msg);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 18:48:03 +03:00
|
|
|
template<typename Mutex>
|
2023-09-24 13:02:30 +03:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::flush()
|
2019-05-08 17:50:23 +03:00
|
|
|
{
|
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
|
flush_();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 18:48:03 +03:00
|
|
|
template<typename Mutex>
|
2023-09-24 13:02:30 +03:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern)
|
2019-05-08 17:50:23 +03:00
|
|
|
{
|
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
|
set_pattern_(pattern);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 18:48:03 +03:00
|
|
|
template<typename Mutex>
|
2023-09-24 13:02:30 +03:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
2019-05-08 17:50:23 +03:00
|
|
|
{
|
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
|
set_formatter_(std::move(sink_formatter));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 18:48:03 +03:00
|
|
|
template<typename Mutex>
|
2023-09-24 13:02:30 +03:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
|
2019-05-08 17:50:23 +03:00
|
|
|
{
|
2023-09-01 18:22:40 +03:00
|
|
|
set_formatter_(std::make_unique<spdlog::pattern_formatter>(pattern));
|
2019-05-08 17:50:23 +03:00
|
|
|
}
|
|
|
|
|
|
2019-05-10 18:48:03 +03:00
|
|
|
template<typename Mutex>
|
2023-09-24 20:34:09 +03:00
|
|
|
void spdlog::sinks::base_sink<Mutex>::set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)
|
2019-05-08 17:50:23 +03:00
|
|
|
{
|
|
|
|
|
formatter_ = std::move(sink_formatter);
|
|
|
|
|
}
|
2023-09-24 20:26:32 +03: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>;
|