File indexing completed on 2025-12-17 10:29:01
0001
0002
0003
0004 #pragma once
0005
0006 #include <spdlog/details/file_helper.h>
0007 #include <spdlog/details/null_mutex.h>
0008 #include <spdlog/details/synchronous_factory.h>
0009 #include <spdlog/sinks/base_sink.h>
0010
0011 #include <mutex>
0012 #include <string>
0013
0014 namespace spdlog {
0015 namespace sinks {
0016
0017
0018
0019 template <typename Mutex>
0020 class basic_file_sink final : public base_sink<Mutex> {
0021 public:
0022 explicit basic_file_sink(const filename_t &filename,
0023 bool truncate = false,
0024 const file_event_handlers &event_handlers = {});
0025 const filename_t &filename() const;
0026
0027 protected:
0028 void sink_it_(const details::log_msg &msg) override;
0029 void flush_() override;
0030
0031 private:
0032 details::file_helper file_helper_;
0033 };
0034
0035 using basic_file_sink_mt = basic_file_sink<std::mutex>;
0036 using basic_file_sink_st = basic_file_sink<details::null_mutex>;
0037
0038 }
0039
0040
0041
0042
0043 template <typename Factory = spdlog::synchronous_factory>
0044 inline std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name,
0045 const filename_t &filename,
0046 bool truncate = false,
0047 const file_event_handlers &event_handlers = {}) {
0048 return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate,
0049 event_handlers);
0050 }
0051
0052 template <typename Factory = spdlog::synchronous_factory>
0053 inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name,
0054 const filename_t &filename,
0055 bool truncate = false,
0056 const file_event_handlers &event_handlers = {}) {
0057 return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate,
0058 event_handlers);
0059 }
0060
0061 }
0062
0063 #ifdef SPDLOG_HEADER_ONLY
0064 #include "basic_file_sink-inl.h"
0065 #endif