diff options
author | puasonych <basargin.erik@gmail.com> | 2018-05-30 10:48:56 +0300 |
---|---|---|
committer | puasonych <basargin.erik@gmail.com> | 2018-05-30 10:48:56 +0300 |
commit | 877a6184008e1af7b17f936c2a1824d4ad6bca14 (patch) | |
tree | 858cf5b026b58da4e72a82b5a9ed59c49044e9f5 | |
parent | eb2118c181455991c768a607ec40ca3b87830388 (diff) |
Update step logger
Fixed bugs with multithreading and added protection against data lost with insufficiently accurate setting of the maximum value of the file size
-rw-r--r-- | include/spdlog/contrib/sinks/step_file_sink.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/include/spdlog/contrib/sinks/step_file_sink.h b/include/spdlog/contrib/sinks/step_file_sink.h index 9010eda4..f4a098d2 100644 --- a/include/spdlog/contrib/sinks/step_file_sink.h +++ b/include/spdlog/contrib/sinks/step_file_sink.h @@ -99,8 +99,11 @@ public: _file_helper.open(_current_filename); _current_size = _file_helper.size(); // expensive. called only once - _current_size += _file_header.formatted.size(); - if (_current_size) _file_helper.write(_file_header); + if (!_current_size) + { + _current_size += _file_header.formatted.size(); + if (_current_size) _file_helper.write(_file_header); + } } ~step_file_sink() @@ -123,14 +126,17 @@ protected: { filename_t new_filename; std::tie(new_filename, std::ignore) = FileNameCalc::calc_filename(_base_filename, _tmp_ext); - if (new_filename != _current_filename) - { - close_current_file(); + + bool change_occured = !details::file_helper::file_exists(new_filename); + if (change_occured) close_current_file(); - // std::tie(_current_filename, std::ignore) = FileNameCalc::calc_filename(_base_filename, _tmp_ext); - _file_helper.open(_current_filename); - _tp = _next_tp(); + _current_filename = std::move(new_filename); + _file_helper.open(_current_filename); + _tp = _next_tp(); + + if (change_occured) + { _current_size = _file_header.formatted.size(); if (_current_size) _file_helper.write(_file_header); } |