What are the best practices for logging in Android apps in production mode, keeping in mind the following requirements :
Ability to upload logs for debugging
Ability to clean up logs or set rollovers
Thanks
Logging levels are usually considered to be in order of importance: turn on "unimportant" levels in development ( trace , debug and the like), but enable only the "most important" levels ( warning , error , etc.) in production, where resources like CPU time and disk space are precious.
The Verbose level logs a message for both the activity start and end, plus the values of the variables and arguments that are used. By default, the Verbose level includes: Execution Started log entry - generated every time a process is started. Execution Ended log entry - generated every time a process is finalized.
Our preference is to automatically upload only exceptions. For client logging we prefer to selectively set a flag or have a special debug version that we give to clients with problems.
Exception catching can be done with Thread. setDefaultUncaughtExceptionHandler(). There are some caveats with this (mainly you need to exit() the app after done with exception handling). See: http://groups.google.com/group/android-developers/browse_thread/thread/c32e8c6120bed5c5/54c28b745c0fca80
For log collection see android-log-collector. No need to use the whole package, see the source and copy-paste.
If you'd like to get the crash reports ACRA can be a good solution.ACRA is a library enabling Android Application to automatically post their crash reports to a GoogleDoc form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With