diff --git a/include/quill/sinks/FileSink.h b/include/quill/sinks/FileSink.h index d47729df..28d69921 100644 --- a/include/quill/sinks/FileSink.h +++ b/include/quill/sinks/FileSink.h @@ -405,17 +405,18 @@ class FileSink : public StreamSink /** * Fsync the file descriptor. */ - void fsync_file() noexcept + void fsync_file(bool force_fsync = false) noexcept { - auto const now = std::chrono::steady_clock::now(); - - if ((now - _last_fsync_timestamp) < _config.minimum_fsync_interval()) + if (!force_fsync) { - return; + auto const now = std::chrono::steady_clock::now(); + if ((now - _last_fsync_timestamp) < _config.minimum_fsync_interval()) + { + return; + } + _last_fsync_timestamp = now; } - _last_fsync_timestamp = now; - #ifdef _WIN32 FlushFileBuffers(reinterpret_cast(_get_osfhandle(_fileno(_file)))); #else diff --git a/include/quill/sinks/RotatingFileSink.h b/include/quill/sinks/RotatingFileSink.h index efa5adf4..bfd1e864 100644 --- a/include/quill/sinks/RotatingFileSink.h +++ b/include/quill/sinks/RotatingFileSink.h @@ -380,7 +380,7 @@ class RotatingFileSink : public FileSink // We need to flush and also fsync before actually getting the size of the file FileSink::flush_sink(); - FileSink::fsync_file(_file); + FileSink::fsync_file(true); if (_get_file_size(_filename) <= 0) {