react-native-file-logger icon indicating copy to clipboard operation
react-native-file-logger copied to clipboard

Log Directory Not Recognized After App Reinstallation

Open ELichto opened this issue 1 year ago • 5 comments

When setting a custom logDirectory, such as /storage/emulated/0/Download/logs/, the library successfully writes logs to the specified directory. However, if the app is uninstalled and then reinstalled, the library fails to recognize the previously set logDirectory. Calling getLogFilePaths() after reinstallation returns an empty array, even though the log files still exist in the directory.

Steps to Reproduce: 1. Configure react-native-file-logger with a custom logDirectory, for example: /storage/emulated/0/Download/logs/. 2. Write logs and verify that log files are created in the specified directory. 3. Uninstall the app. 4. Reinstall the app. 5. the app fails to write logs... calling getLogFilePaths return an empty array. Edit: Tested only on android

ELichto avatar Jan 11 '25 11:01 ELichto

I'm having the same issue

FlorinPopaPersonal avatar Jan 21 '25 13:01 FlorinPopaPersonal

After some investigation, I found out that this is related to file permissions. After uninstalling and reinstalling the app, your app gets a different app ID so the owner of the previously created files is the previous instance of the app and as a result of that you cannot change anything to the existing files. My solution was to install react-native-device-info and inside the logs folder create new folders with the instance id of the installation, in that way having different folders with logs, corresponding to each installation of the app. Hope that helps anyone

FlorinPopaPersonal avatar Jan 30 '25 14:01 FlorinPopaPersonal

I am facing the same issue. This only happens after a fresh app installation. If I reopen the app, the issue no longer occurs.

JJSLIoT avatar Sep 17 '25 07:09 JJSLIoT

I mitigated this issue by calling the FileLogger.configure({...}); twice after a delay of 1s.

JJSLIoT avatar Sep 17 '25 07:09 JJSLIoT

@alois-beto This has become a MAJOR issue for us, actually. Apparently, the above workaround does not always work, and logs recorded immediately after the app starts are sometimes not written to the log file.

JJSLIoT avatar Oct 15 '25 07:10 JJSLIoT