I'm using microlog4android to log to file. The question is how can set maximum file size?
microlog4android FileAppender class has two methods: getLogSize (which always return -1 ) and clear. I could clear log when it reaches certain size but getLogSize doesn't seem to work.
Is there any better, more mature android logging solution that I'm not aware of?
You can use logback-android with the
RollingFileAppender
andSizeBasedTriggeringPolicy
, but you should be aware of a bug (src) that may cause your working log file to exceed the max file size. A workaround is to subclass the triggering policy to bypass the bug:Here's an example config (based on the Logback manual and including the workaround above) that you can put into your AndroidManifest.xml. I tested this in Android 4.0.3 emulator, but I imagine it would also work in earlier versions.
May be you can use normal File apis to retrieve file length and then delete/rename it before initializing Logger if it exceeds size limit.