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 | |
15 | template<typename Mutex> |
16 | SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink() |
17 | : formatter_{details::make_unique<spdlog::pattern_formatter>()} |
18 | {} |
19 | |
20 | template<typename Mutex> |
21 | SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink(std::unique_ptr<spdlog::formatter> formatter) |
22 | : formatter_{std::move(formatter)} |
23 | {} |
24 | |
25 | template<typename Mutex> |
26 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg) |
27 | { |
28 | std::lock_guard<Mutex> lock(mutex_); |
29 | sink_it_(msg); |
30 | } |
31 | |
32 | template<typename Mutex> |
33 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::flush() |
34 | { |
35 | std::lock_guard<Mutex> lock(mutex_); |
36 | flush_(); |
37 | } |
38 | |
39 | template<typename Mutex> |
40 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern) |
41 | { |
42 | std::lock_guard<Mutex> lock(mutex_); |
43 | set_pattern_(pattern); |
44 | } |
45 | |
46 | template<typename Mutex> |
47 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) |
48 | { |
49 | std::lock_guard<Mutex> lock(mutex_); |
50 | set_formatter_(std::move(sink_formatter)); |
51 | } |
52 | |
53 | template<typename Mutex> |
54 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern) |
55 | { |
56 | set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern)); |
57 | } |
58 | |
59 | template<typename Mutex> |
60 | void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter) |
61 | { |
62 | formatter_ = std::move(sink_formatter); |
63 | } |
64 | |