| 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. |
|---|---|
| 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #ifndef SPDLOG_HEADER_ONLY |
| 7 | #include <spdlog/sinks/base_sink.h> |
| 8 | #endif |
| 9 | |
| 10 | #include <spdlog/common.h> |
| 11 | #include <spdlog/pattern_formatter.h> |
| 12 | |
| 13 | #include <memory> |
| 14 | #include <mutex> |
| 15 | |
| 16 | template <typename Mutex> |
| 17 | SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink() |
| 18 | : formatter_{details::make_unique<spdlog::pattern_formatter>()} {} |
| 19 | |
| 20 | template <typename Mutex> |
| 21 | SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink( |
| 22 | std::unique_ptr<spdlog::formatter> formatter) |
| 23 | : formatter_{std::move(formatter)} {} |
| 24 | |
| 25 | template <typename Mutex> |
| 26 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg) { |
| 27 | std::lock_guard<Mutex> lock(mutex_); |
| 28 | sink_it_(msg); |
| 29 | } |
| 30 | |
| 31 | template <typename Mutex> |
| 32 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::flush() { |
| 33 | std::lock_guard<Mutex> lock(mutex_); |
| 34 | flush_(); |
| 35 | } |
| 36 | |
| 37 | template <typename Mutex> |
| 38 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern) { |
| 39 | std::lock_guard<Mutex> lock(mutex_); |
| 40 | set_pattern_(pattern); |
| 41 | } |
| 42 | |
| 43 | template <typename Mutex> |
| 44 | void SPDLOG_INLINE |
| 45 | spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) { |
| 46 | std::lock_guard<Mutex> lock(mutex_); |
| 47 | set_formatter_(std::move(sink_formatter)); |
| 48 | } |
| 49 | |
| 50 | template <typename Mutex> |
| 51 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern) { |
| 52 | set_formatter_(details::make_unique<spdlog::pattern_formatter>(args: pattern)); |
| 53 | } |
| 54 | |
| 55 | template <typename Mutex> |
| 56 | void SPDLOG_INLINE |
| 57 | spdlog::sinks::base_sink<Mutex>::set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter) { |
| 58 | formatter_ = std::move(sink_formatter); |
| 59 | } |
| 60 |