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
13namespace spdlog {
14namespace sinks {
15
16template <typename Mutex>
17SPDLOG_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
24template <typename Mutex>
25SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const {
26 return file_helper_.filename();
27}
28
29template <typename Mutex>
30SPDLOG_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
36template <typename Mutex>
37SPDLOG_INLINE void basic_file_sink<Mutex>::flush_() {
38 file_helper_.flush();
39}
40
41} // namespace sinks
42} // namespace spdlog
43