diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index 350c2127..4dc04f2d 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -35,7 +35,7 @@ SPDLOG_INLINE rotating_file_sink::rotating_file_sink( { throw_spdlog_ex("rotating sink constructor: max_size arg cannot be zero"); } - + if (max_files > 200000) { throw_spdlog_ex("rotating sink constructor: max_files arg cannot exceed 200000"); @@ -71,6 +71,24 @@ SPDLOG_INLINE filename_t rotating_file_sink::filename() return file_helper_.filename(); } +template +SPDLOG_INLINE std::size_t rotating_file_sink::get_max_size() const +{ + std::lock_guard lock(base_sink::mutex_); + return max_size_; +} + +template +SPDLOG_INLINE void rotating_file_sink::set_max_size(const std::size_t max_size) +{ + std::lock_guard lock(base_sink::mutex_); + if (max_size == 0) + { + throw_spdlog_ex("rotating sink set_max_size: max_size cannot be zero"); + } + max_size_ = max_size; +} + template SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &msg) { diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index ce0d7b1e..5b18e771 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -26,6 +26,8 @@ public: const file_event_handlers &event_handlers = {}); static filename_t calc_filename(const filename_t &filename, std::size_t index); filename_t filename(); + std::size_t get_max_size() const; + void set_max_size(const std::size_t max_size); protected: void sink_it_(const details::log_msg &msg) override;