From 0b48976be49a69d8ee30b9b153b261704bbc02a0 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 5 Feb 2022 19:45:19 +0200 Subject: [PATCH] flush before rotating --- include/spdlog/sinks/rotating_file_sink-inl.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index e32e20d4..050a3e6c 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -76,10 +76,14 @@ SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &m // rotate if the new estimated file size exceeds max size. // rotate only if the real size > 0 to better deal with full disk (see issue #2261). // we only check the real size when new_size > max_size_ because it is relatively expensive. - if (new_size > max_size_ && file_helper_.size() > 0) + if (new_size > max_size_) { - rotate_(); - new_size = formatted.size(); + file_helper_.flush(); + if(file_helper_.size() > 0) + { + rotate_(); + new_size = formatted.size(); + } } file_helper_.write(formatted); current_size_ = new_size;