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/basic_file_sink.h> |
8 | #endif |
9 | |
10 | #include <spdlog/common.h> |
11 | #include <spdlog/details/os.h> |
12 | |
13 | namespace spdlog { |
14 | namespace sinks { |
15 | |
16 | template<typename Mutex> |
17 | SPDLOG_INLINE basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers) |
18 | : file_helper_{event_handlers} |
19 | { |
20 | file_helper_.open(filename, truncate); |
21 | } |
22 | |
23 | template<typename Mutex> |
24 | SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const |
25 | { |
26 | return file_helper_.filename(); |
27 | } |
28 | |
29 | template<typename Mutex> |
30 | SPDLOG_INLINE void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg) |
31 | { |
32 | memory_buf_t formatted; |
33 | base_sink<Mutex>::formatter_->format(msg, formatted); |
34 | file_helper_.write(formatted); |
35 | } |
36 | |
37 | template<typename Mutex> |
38 | SPDLOG_INLINE void basic_file_sink<Mutex>::flush_() |
39 | { |
40 | file_helper_.flush(); |
41 | } |
42 | |
43 | } // namespace sinks |
44 | } // namespace spdlog |
45 |