spdlog/src/sinks/basic_file_sink.cpp

44 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)
2023-09-24 18:27:26 +08:00
#include <spdlog/sinks/basic_file_sink.h>
2019-05-13 05:09:00 +08:00
#include <spdlog/common.h>
#include <spdlog/details/os.h>
2019-05-13 04:36:48 +08:00
namespace spdlog {
namespace sinks {
template<typename Mutex>
2023-09-25 01:43:14 +08:00
basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers)
2021-11-11 00:08:24 +08:00
: file_helper_{event_handlers}
2019-05-13 04:36:48 +08:00
{
file_helper_.open(filename, truncate);
}
template<typename Mutex>
2023-09-25 01:43:14 +08:00
const filename_t &basic_file_sink<Mutex>::filename() const
2019-05-13 04:36:48 +08:00
{
return file_helper_.filename();
}
template<typename Mutex>
2023-09-25 01:43:14 +08:00
void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
2019-05-13 04:36:48 +08:00
{
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
2019-05-13 04:36:48 +08:00
file_helper_.write(formatted);
}
template<typename Mutex>
2023-09-25 01:43:14 +08:00
void basic_file_sink<Mutex>::flush_()
2019-05-13 04:36:48 +08:00
{
file_helper_.flush();
}
} // 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>;