Search code examples
androidandroid-logcatandroid-debug

Good Logging Techniques for Android


I wish to introduce some logging to an android application that I'm taking over. I wish to be able to reference this log file during developing, and to get a copy of the log if a customer has issues while the program is in production.

Since this would be in production, I would like the make the log file into a rolling log, so it doesn't consume too many resources.

In some android examples I noticed import android.util.Log;. I'm curious if this is a standard way of logging for android. If not, what is a good way of doing this (e.g. I really like log4j when coding in java.)?

  1. Can android.util.log do a rolling log like I'm requesting?

  2. Where does android.util.Log write to by default?

  3. If just to console, is there a way to write this to a rolling log file on the android device, which can then be emailed if there is a problem with the program?


Solution

  • Can android.util.log do a rolling log like I'm requesting?

    1) Not like you requested. The logs will be rolling but for all applications on the device, not just your app.

    Where does android.util.Log write to by default?

    2) The Android logging system, which can be viewed through logcat. Think of it like the Windows Event logs if you are familiar with that. I would download a logcat program and scroll through your system logs to familiarize yourself with them.

    If just to console, is there a way to write this to a rolling log file on the android device, which can then be emailed if there is a problem with the program?

    3) You could write your own rolling log to the filesystem and then email it. However, you would have to implement this functionality. You could also try seeing if there are any 3rd party logging tools/libraries that may satisfy your needs.