diff --git a/include/spdlog/sinks/periodic_file_sink.h b/include/spdlog/sinks/periodic_file_sink.h index 6f03c4bf..2c8cff3b 100644 --- a/include/spdlog/sinks/periodic_file_sink.h +++ b/include/spdlog/sinks/periodic_file_sink.h @@ -3,7 +3,7 @@ //File: minute_file_sink to support every 1 min file rotation. //example driver code: // auto duration{std::chrono::minutes{1}}; -//auto logger = spdlog::periodic_logger_mt("periodic_logger", "logs/min-log.txt",false,60,duration); +//auto logger = spdlog::periodic_logger_mt("periodic_logger", "logs/min-log.txt",duration,60,false); #pragma once @@ -50,18 +50,26 @@ class periodic_file_sink final : public base_sink { public: // create every periodic file sink which rotates on given time - periodic_file_sink( + /*periodic_file_sink( filename_t base_filename, bool truncate = false, uint16_t max_files = 0, std::chrono::duration rotation_period = 0, const file_event_handlers &event_handlers = {}) + + */ + periodic_file_sink( + filename_t base_filename, + std::chrono::minutes rotation_interval, + uint16_t max_files, + bool truncate_first = false, + const file_event_handlers &event_handlers = {}) : base_filename_(std::move(base_filename)) , file_helper_{event_handlers} - , truncate_(truncate) + , truncate_(truncate_first) , max_files_(max_files) - ,rotation_p_(rotation_period) + ,rotation_p_(rotation_interval) , filenames_q_() { - if (rotation_period <= std::chrono::minutes(0)) + if (rotation_interval <= std::chrono::minutes(0)) { throw_spdlog_ex("periodic_file_sink: Invalid rotation time in ctor"); } @@ -76,6 +84,12 @@ public: { init_filenames_q_(); } + + if (max_files > 2000) + { + throw_spdlog_ex("periodic_file_sink: max_files param exceeds max of 2000"); + } + } filename_t filename() @@ -202,16 +216,16 @@ using periodic_file_sink_st = periodic_file_sink; // factory functions // template -inline std::shared_ptr periodic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false, - uint16_t max_files = 0, std::chrono::duration period = 1, const file_event_handlers &event_handlers = {}) +inline std::shared_ptr periodic_logger_mt(const std::string &logger_name, const filename_t &filename,std::chrono::minutes period = 1,uint16_t max_files = 0, bool truncate = false, + const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, max_files, period ,event_handlers); + return Factory::template create(logger_name, filename,period,max_files, truncate, event_handlers); } template -inline std::shared_ptr periodic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false, - uint16_t max_files = 0,std::chrono::duration period = 1, const file_event_handlers &event_handlers = {}) +inline std::shared_ptr periodic_logger_st(const std::string &logger_name, const filename_t &filename,std::chrono::minutes period = 1,uint16_t max_files = 0, bool truncate = false, + const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, max_files, period, event_handlers); + return Factory::template create(logger_name, filename,period, max_files,truncate, event_handlers); } } // namespace spdlog