From 9d85fa801c89395ff99be50b3872c8293774a62a Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 13 Nov 2014 17:40:27 +0000 Subject: [PATCH 1/2] Fix whitespace - 4 spaces indent --- include/spdlog/sinks/file_sinks.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 847af960..e430dc48 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -111,8 +111,8 @@ private: // Rotate files: // log.txt -> log.1.txt - // log.1.txt -> log2.txt - // log.2.txt -> log3.txt + // log.1.txt -> log.2.txt + // log.2.txt -> log.3.txt // log.3.txt -> delete @@ -125,12 +125,12 @@ private: std::string target = calc_filename(_base_filename, i, _extension); if (details::file_helper::file_exists(target)) - { - if (std::remove(target.c_str()) != 0) - { - throw spdlog_ex("rotating_file_sink: failed removing " + target); - } - } + { + if (std::remove(target.c_str()) != 0) + { + throw spdlog_ex("rotating_file_sink: failed removing " + target); + } + } if (details::file_helper::file_exists(src) && std::rename(src.c_str(), target.c_str())) { throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target); @@ -138,9 +138,9 @@ private: } auto cur_name = _file_helper.filename(); if (std::remove(cur_name.c_str()) != 0) - { - throw spdlog_ex("rotating_file_sink: failed removing " + cur_name); - } + { + throw spdlog_ex("rotating_file_sink: failed removing " + cur_name); + } _file_helper.open(cur_name); } std::string _base_filename; From 66bb651362c1327c8dd08a767ffce36fcb9e7e08 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 13 Nov 2014 18:22:31 +0000 Subject: [PATCH 2/2] Fixup file rotation logic --- include/spdlog/sinks/file_sinks.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index e430dc48..5dc3e6d9 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -72,13 +72,13 @@ class rotating_file_sink : public base_sink public: rotating_file_sink(const std::string &base_filename, const std::string &extension, std::size_t max_size, std::size_t max_files, - std::size_t flush_inverval=0): + std::size_t flush_interval=0): _base_filename(base_filename), _extension(extension), _max_size(max_size), _max_files(max_files), _current_size(0), - _file_helper(flush_inverval) + _file_helper(flush_interval) { _file_helper.open(calc_filename(_base_filename, 0, _extension)); } @@ -119,7 +119,7 @@ private: void _rotate() { _file_helper.close(); - for (auto i = _max_files; i > 0; --i) + for (auto i = _max_files - 1; i > 0; --i) { std::string src = calc_filename(_base_filename, i - 1, _extension); std::string target = calc_filename(_base_filename, i, _extension); @@ -137,9 +137,9 @@ private: } } auto cur_name = _file_helper.filename(); - if (std::remove(cur_name.c_str()) != 0) + if (details::file_helper::file_exists(cur_name)) { - throw spdlog_ex("rotating_file_sink: failed removing " + cur_name); + throw spdlog_ex("rotating_file_sink: " + cur_name + " still exists after rotating"); } _file_helper.open(cur_name); }