diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index ce140415..aedaf52f 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,19 @@ struct daily_filename_calculator } }; +/* + * Generator of daily log file names by formatting + */ +struct daily_filename_format_calculator +{ + // Create filename by formatting %Y_%m_%d.log + static filename_t calc_filename (const filename_t &filename, const tm &now_tm) + { + filename_t fmt_filename = fmt::format(SPDLOG_FILENAME_T ("{{:{}}}"), filename); + return fmt::format(fmt_filename, now_tm); + } +}; + /* * Rotating file sink based on date. * If truncate != false , the created file will be truncated. @@ -182,6 +196,8 @@ private: using daily_file_sink_mt = daily_file_sink; using daily_file_sink_st = daily_file_sink; +using daily_file_format_sink_mt = daily_file_sink; +using daily_file_format_sink_st = daily_file_sink; } // namespace sinks @@ -195,10 +211,24 @@ inline std::shared_ptr daily_logger_mt( return Factory::template create(logger_name, filename, hour, minute, truncate, max_files); } +template +inline std::shared_ptr daily_logger_format_mt( + const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0) +{ + return Factory::template create(logger_name, filename, hour, minute, truncate, max_files); +} + template inline std::shared_ptr daily_logger_st( const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0) { return Factory::template create(logger_name, filename, hour, minute, truncate, max_files); } + +template +inline std::shared_ptr daily_logger_format_st( + const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false, uint16_t max_files = 0) +{ + return Factory::template create(logger_name, filename, hour, minute, truncate, max_files); +} } // namespace spdlog