Search code examples
tinylog

Using File Logger with Tinylog 1.3.5 on Android 9.0


Does Tinylog 1.3.5 (the latest 1.x.x version) support logging into files on Android?

I have tried to get it to work but to no avail. Logging via catlog works. Configuring tinylog via a "tinylog.properties" file also works, as long as "tinylog.writer = catlog".

But even when using this simple tinylog.properties file, no logging file is created:

tinylog.writer = file
tinylog.writer.filename = log.txt

When using version 2.0.0-M2.1 of Tinylog the project compiles but non of the logging commands (Logger.info, Logger.error, etc.) seems to do anything. The target device runs Android SDK 28.


Solution:

This worked for me:

tinylog.writer = file 
tinylog.writer.filename = /data/user/0/com.apppackage.my/files/log.txt

Solution

  • Yes, tinylog supports logging into files on Android. However, the target folder has to be writable for your app. Have you tried tinylog.writer.filename = /data/local/tmp/log.txt for example? If you use an emulator, you get usually tons of logcat output. This output can be helpful to find the cause for the problem. This will probably be missing write permissions of the app for the target folder of the log file.

    For tinylog 2, the configuration syntax has been simplified. In your case, your tinylog.properties would be:

    writer       = file
    writer.file  = /data/local/tmp/log.txt