| 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, |
| 18 | bool truncate, |
| 19 | const file_event_handlers &event_handlers) |
| 20 | : file_helper_{event_handlers} { |
| 21 | file_helper_.open(fname: filename, truncate); |
| 22 | } |
| 23 | |
| 24 | template <typename Mutex> |
| 25 | SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const { |
| 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 | memory_buf_t formatted; |
| 32 | base_sink<Mutex>::formatter_->format(msg, formatted); |
| 33 | file_helper_.write(buf: formatted); |
| 34 | } |
| 35 | |
| 36 | template <typename Mutex> |
| 37 | SPDLOG_INLINE void basic_file_sink<Mutex>::flush_() { |
| 38 | file_helper_.flush(); |
| 39 | } |
| 40 | |
| 41 | } // namespace sinks |
| 42 | } // namespace spdlog |
| 43 |