问题
关于:std::make_shared<spdlog::sinks::rotating_file_sink_mt> 第一参数大多数例子,包括头文件中给的都是 "logs/log.txt" 字符串样式
代码中使用 string 还是 转成 char * 使用?
查看源码
spdlog.h 中
// Example:
// auto mylogger = std::make_shared<spdlog::logger>("mylogger", ...);
// spdlog::initialize_logger(mylogger);
未明确标明用法
进一步查看
spdlog/sinks/rotating_file_sink.h
21 template <typename Mutex>
22 class rotating_file_sink final : public base_sink<Mutex> {
23 public:
24 rotating_file_sink(filename_t base_filename,
25 std::size_t max_size,
26 std::size_t max_files,
27 bool rotate_on_open = false,
28 const file_event_handlers &event_handlers = {});
29 static filename_t calc_filename(const filename_t &filename, std::size_t index);
30 filename_t filename();
31
32 protected:
33 void sink_it_(const details::log_msg &msg) override;
34 void flush_() override;
35
36 private:
37 // Rotate files:
38 // log.txt -> log.1.txt
39 // log.1.txt -> log.2.txt
40 // log.2.txt -> log.3.txt
41 // log.3.txt -> delete
42 void rotate_();
43
44 // delete the target if exists, and rename the src file to target
45 // return true on success, false otherwise.
46 bool rename_file_(const filename_t &src_filename, const filename_t &target_filename);
47
48 filename_t base_filename_;
49 std::size_t max_size_;
50 std::size_t max_files_;
51 std::size_t current_size_;
52 details::file_helper file_helper_;
53 };
54
55 using rotating_file_sink_mt = rotating_file_sink<std::mutex>;
56 using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
include/spdlog/common.h
131 #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
132 using filename_t = std::wstring;
133 // allow macro expansion to occur in SPDLOG_FILENAME_T
134 #define SPDLOG_FILENAME_T_INNER(s) L##s
135 #define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s)
136 #else
137 using filename_t = std::string;
138 #define SPDLOG_FILENAME_T(s) s
139 #endif
328 struct file_event_handlers {
329 file_event_handlers()
330 : before_open(nullptr),
331 after_open(nullptr),
332 before_close(nullptr),
333 after_close(nullptr) {}
334
335 std::function<void(const filename_t &filename)> before_open;
336 std::function<void(const filename_t &filename, std::FILE *file_stream)> after_open;
337 std::function<void(const filename_t &filename, std::FILE *file_stream)> before_close;
338 std::function<void(const filename_t &filename)> after_close;
339 };
结论
可以看出 参数依次为:
std::string;std::size_t;std::size_t;bool;const file_event_handlers&
7140

被折叠的 条评论
为什么被折叠?



