From 4f65fcd7b18b9d1aac29191a9f2821934712d843 Mon Sep 17 00:00:00 2001 From: Philip Miller Date: Thu, 24 Jan 2019 09:19:52 -0500 Subject: [PATCH] remove minor optimization for the sake of simplicity --- include/spdlog/sinks/rotating_file_sink.h | 24 +++++++---------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index b2f52226..ae0f70f6 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -36,15 +36,12 @@ public: , max_size_(max_size) , max_files_(max_files) { - if (rotate_on_open) - { - rotate_(false); - } - else - { - file_helper_.open(calc_filename(base_filename_, 0)); - } + file_helper_.open(calc_filename(base_filename_, 0)); current_size_ = file_helper_.size(); // expensive. called only once + if (rotate_on_open && current_size_ > 0) + { + rotate_(); + } } // calc filename according to index and file extension if exists. @@ -95,7 +92,7 @@ private: // log.1.txt -> log.2.txt // log.2.txt -> log.3.txt // log.3.txt -> delete - void rotate_(bool reopen=true) + void rotate_() { using details::os::filename_to_str; file_helper_.close(); @@ -123,14 +120,7 @@ private: } } } - if (reopen) - { - file_helper_.reopen(true); - } - else - { - file_helper_.open(base_filename_, true); - } + file_helper_.reopen(true); } // delete the target if exists, and rename the src file to target