From a9abfbb005539385607327f14cfc7495128ee44b Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 15 Nov 2014 18:42:53 +0200 Subject: [PATCH] Fixed rotate bug --- include/spdlog/details/file_helper.h | 8 ++++++++ include/spdlog/sinks/file_sinks.h | 7 +------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index da389d8d..f6aa5a3e 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -80,6 +80,14 @@ public: throw spdlog_ex("Failed opening file " + fname + " for writing"); } + void reopen() + { + if(_filename.empty()) + throw spdlog_ex("Failed re opening file - was not opened before"); + open(_filename); + + } + void close() { if (_fd) diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 847af960..8e9c1485 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -136,12 +136,7 @@ private: throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target); } } - auto cur_name = _file_helper.filename(); - if (std::remove(cur_name.c_str()) != 0) - { - throw spdlog_ex("rotating_file_sink: failed removing " + cur_name); - } - _file_helper.open(cur_name); + _file_helper.reopen(); } std::string _base_filename; std::string _extension;