plog icon indicating copy to clipboard operation
plog copied to clipboard

Adding possibility for force flushing current file buffer

Open AJIOB opened this issue 1 year ago • 4 comments

Sometimes will be interested in force flushing RollingFileAppender data for next backuping them into different storages.

I usually have only one file for logging (without any backup). That is why it is not possible for using rollLogFiles() call.

If user wants to force use flush, it will be also good for providing all collected logs without removing any part of collected logs. Force rolling removes last of them - and that is not looks like a good choice for that case.

AJIOB avatar Nov 30 '22 07:11 AJIOB

Log data is written directly to a file without any intermediate buffering in the app. So I'm not sure what flushing do you need. Could you provide more details?

SergiusTheBest avatar Dec 06 '22 15:12 SergiusTheBest

@SergiusTheBest As you know, any OS and libc have possibility for using file buffering internally for optimization purposes (block writing and so on).

And a programmer can force write that buffers to HDD/SSD/... by special API call.

C/C++ has few standardized API for flushing data:

  • https://en.cppreference.com/w/c/io/fflush
  • https://en.cppreference.com/w/cpp/io/c/fflush
  • https://en.cppreference.com/w/cpp/io/basic_ostream/flush

If you need to use raw OS calls, you can use sync() Linux call for that purposes:

  • https://linux.die.net/man/2/sync

I think that Windows provides the similar API for that operation too.

With regards, Alex

AJIOB avatar Dec 06 '22 15:12 AJIOB

Oh, I think I see your problem. Your backup system works on the block level so you want the log data to be written on the disk. Is that correct?

SergiusTheBest avatar Dec 06 '22 15:12 SergiusTheBest

Yes, you are right.

Also, glibc uses internal RAM buffers too, as I know, and another process sometimes have no possibility for accessing the latest file changes on HDD/SSD...

AJIOB avatar Dec 06 '22 16:12 AJIOB