tinylog icon indicating copy to clipboard operation
tinylog copied to clipboard

Log file is not created on Android on power shutdown

Open recser opened this issue 1 year ago • 6 comments

Describe the bug The Android application is not creating the log file(and not logging) when the device is forcefully shutdown(power taken off)

To Reproduce Steps to reproduce the behavior:

  1. Shutdown the device by removing the plug
  2. Start the device, start the application

Environment tinylog version: 2.4.1 Java version: 17

recser avatar Oct 24 '24 11:10 recser

What is your tinylog configuration?

pmwmedia avatar Jan 04 '25 00:01 pmwmedia

Hi, this is the configuration :

writer1          = logcat
writer1.level=debug
writer1.format   = {message}

writer2          = rolling file
writer2.level=info
writer2.file=#{tinylog.directory}/{pid}_LOG_{date:yyyy-MM-dd_HH-mm-ss}.txt
writer2.backups  = 1000
writer2.format   = {date: HH:mm:ss.SSS} {level}: {message}
writer2.policies = size: 5mb

recser avatar Jan 04 '25 10:01 recser

What path do use as #{tinylog.directory}? Are you sure that log entries have already been issued before you shut down the device?

According to your configuration, you don't use the writing thread nor buffering. Therefore, tinylog writes all log entries directly into the log files. Maybe there is some buffering from Android itself that prevents persisting the log file before shutdown!?

pmwmedia avatar Jan 04 '25 22:01 pmwmedia

Hi, i tried to use different locations (first the app folder, now i use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)), i am running on Android 10. I am not using any threds or buffering and still the data is not written into the file occasionally after an uncontrolled shutdown. The only thing i saw on the devices is that after shutdown it leaves a zombie process in the task manager but since i am using the PID and the data in the name of the file it should not affect the creation or logging into the file for a new instance. I am also using an atomic number to track the number of instances created in order to stop multiple instances being lunched.

No idea why it does this, but it only works if I shutdown the app manually and start it normally again.

recser avatar Jan 05 '25 15:01 recser

Do you see the log file with the log entries before the shutdown when the app is still running? Do you see the missing log entries in Logcat?

pmwmedia avatar Jan 13 '25 18:01 pmwmedia

Hi, yes the file is there. Logcat entries are also present but when the device starts the file is not creating. Seems like there is a lock on the folder of the log files

recser avatar Jan 21 '25 16:01 recser