spdlog/src/sinks/basic_file_sink.cpp

41 lines
1.2 KiB
C++
Raw Normal View History

2019-06-04 05:09:16 +08:00
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2019-05-13 04:36:48 +08:00
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#include "spdlog/sinks/basic_file_sink.h"
2019-05-13 05:09:00 +08:00
#include "spdlog/common.h"
2019-05-13 04:36:48 +08:00
namespace spdlog {
namespace sinks {
2023-09-25 07:35:55 +08:00
template <typename Mutex>
basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename,
bool truncate,
const file_event_handlers &event_handlers)
: file_helper_{event_handlers} {
2019-05-13 04:36:48 +08:00
file_helper_.open(filename, truncate);
}
2023-09-25 07:35:55 +08:00
template <typename Mutex>
const filename_t &basic_file_sink<Mutex>::filename() const {
2019-05-13 04:36:48 +08:00
return file_helper_.filename();
}
2023-09-25 07:35:55 +08:00
template <typename Mutex>
void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg) {
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
2019-05-13 04:36:48 +08:00
file_helper_.write(formatted);
}
2023-09-25 07:35:55 +08:00
template <typename Mutex>
void basic_file_sink<Mutex>::flush_() {
2019-05-13 04:36:48 +08:00
file_helper_.flush();
}
2023-09-25 21:40:05 +08:00
} // namespace sinks
} // namespace spdlog
2023-09-25 01:26:32 +08:00
// template instantiations
template class SPDLOG_API spdlog::sinks::basic_file_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::basic_file_sink<spdlog::details::null_mutex>;