Lumberjack icon indicating copy to clipboard operation
Lumberjack copied to clipboard

File Returned By getAllExistingLogFiles() Does Not Exist

Open rs-georg opened this issue 3 years ago • 1 comments

We have a mechanism in our app to export all log files. To get the available log files we invoke FileLoggingSetup#getAllExistingLogFiles(). We then copy the files into a different directory that contains other diagnostic files and then zip this folder.

However, while copying the files we noticed that some files returned by getAllExistingLogFiles() do not exist and we get an error while copying.

I looked into the source of FileLoggingSetup but couldn't find anything suspicious that would explain this. It's just weird that a file contained in the returned list does not actually exist.

Lumberjack Version 5.0.3

config.getAllExistingLogFiles().forEach {
            try {
                it.copyTo(File(targetDirectory, it.name))
            } catch (error: Throwable) {
                // here we get the error: The source file doesn't exist.
            }
        }

rs-georg avatar Jan 04 '22 14:01 rs-georg

If you check out the source code of v5.0.3 you can see following:

https://github.com/MFlisar/Lumberjack/blob/94e25a63a18b6d4c6a921806c04818cfaa916d85/library-filelogger/src/main/java/com/michaelflisar/lumberjack/FileLoggingSetup.kt#L18

https://github.com/MFlisar/Lumberjack/blob/94e25a63a18b6d4c6a921806c04818cfaa916d85/library-filelogger/src/main/java/com/michaelflisar/lumberjack/FileLoggingSetup.kt#L95-L101

This is a system function with a custom filter on top of it, so when this function is run all returned files should exist. Maybe the rollover policy is sometimes influencing your result? If there are logs being written between the getAllExistingLogFiles and the end of the iteration (in your example there is not much time for this, but theoretically its possible) this may lead to the deletion of a file.

Other than that I've no idea what can cause this, but as I don't see any problems in the code I'd suggest to simply check if the file exists before copying it

MFlisar avatar Jan 07 '22 09:01 MFlisar

No further information and I can't reproduce that so I'll close that.

MFlisar avatar Oct 19 '22 13:10 MFlisar