|
| 1 | +diff --git a/libs/log/src/text_file_backend.cpp b/src/text_file_backend.cpp |
| 2 | +index 8b8920e..0df9a37 100644 |
| 3 | +--- a/libs/log/src/text_file_backend.cpp |
| 4 | ++++ b/libs/log/src/text_file_backend.cpp |
| 5 | +@@ -1422,6 +1422,7 @@ BOOST_LOG_API void text_file_backend::consume(record_view const& rec, string_typ |
| 6 | + rotate_file(); |
| 7 | + } |
| 8 | + |
| 9 | ++ const unsigned int last_file_counter = m_pImpl->m_FileCounter - 1u; |
| 10 | + while (!m_pImpl->m_File.is_open()) |
| 11 | + { |
| 12 | + filesystem::path new_file_name; |
| 13 | +@@ -1464,6 +1465,7 @@ BOOST_LOG_API void text_file_backend::consume(record_view const& rec, string_typ |
| 14 | + else |
| 15 | + { |
| 16 | + prev_file_name.swap(new_file_name); |
| 17 | ++ use_prev_file_name = false; |
| 18 | + } |
| 19 | + |
| 20 | + filesystem::create_directories(new_file_name.parent_path()); |
| 21 | +@@ -1479,9 +1481,11 @@ BOOST_LOG_API void text_file_backend::consume(record_view const& rec, string_typ |
| 22 | + m_pImpl->m_FileName.swap(new_file_name); |
| 23 | + m_pImpl->m_IsFirstFile = false; |
| 24 | + |
| 25 | +- // Check the file size before invoking the open handler, as it may write more data to the file |
| 26 | ++ // Check the file size before invoking the open handler, as it may write more data to the file. |
| 27 | ++ // Only do this check if we haven't exhausted the file counter to avoid looping indefinitely. |
| 28 | + m_pImpl->m_CharactersWritten = static_cast< std::streamoff >(m_pImpl->m_File.tellp()); |
| 29 | +- if (m_pImpl->m_CharactersWritten + formatted_message.size() >= m_pImpl->m_FileRotationSize) |
| 30 | ++ if (m_pImpl->m_CharactersWritten > 0 && m_pImpl->m_CharactersWritten + formatted_message.size() >= m_pImpl->m_FileRotationSize && |
| 31 | ++ m_pImpl->m_FileCounter != last_file_counter) |
| 32 | + { |
| 33 | + // Avoid running the close handler, as we haven't run the open handler yet |
| 34 | + struct close_handler_backup_guard |
| 35 | + |
0 commit comments