MEONMedical / Log4Qt

Log4Qt - Logging for the Qt cross-platform application framework
Apache License 2.0
580 stars 234 forks source link

How to ensure log write to file on disk? #44

Closed Wzshun closed 2 years ago

Wzshun commented 4 years ago

I use DailyFileAppender to write log, but when my program crashed or something broken, it can't see the latest log in file after restart program or reboot.(here is embedded Linux).

The WriteAppender use QTextStream::flush when immediateFlush is true, but it seems that it just only write it's internal buffer to filesystem.

Is there any something like QSaveFile which commit() save data to file? In fact, it call native sync method, which call fsync in linux.

Thanks in advance.

andibacher commented 2 years ago

I don't think that the log4qt library can ensure that the last log entry is written if the application crashes.

"QSaveFile is an I/O device for writing text and binary files, without losing existing data if the writing operation fails" -> QSaveFile does only protect existing data.