Today, I'm talking about Logging in Android. I'll talk about default realisation of logging some events and most popular alternative for Logging in Android development.
Firstly I want to talk about storing logs in Android OS. Android have some spaces for storing logs.
/dev/log/kernel- kernel's logs
/dev/log/radio- log messages from GSM, etc
/dev/log/events- logs from user space application
/dev/log/main- other logs
Next I want to talk about standard opportunity for logging events in any application. For logging some event you can use Log class from Android SDK. This realisation was added in API 1.
Default realisation allow to use different levels for logs:
- DEBUG -
- ERROR -
- INFO -
- VERBOSE -
- WARN -
Android Studio have really good tool for analyse logs - it's
logcat. (In Android Studio you can open it, clicked View -> Tool Windows -> Android Monitor). Android monitor support changing Log level (Assert, Debug, Error, Info, Verbose, Warn).
private static final String TAG = this.getClass().getSimpleName(); ... Log.v(TAG, "index = " + i);
Logging is really useful thing for development process. But unfortunately standard realisation of logs have some disadvantages:
Log.*write logs in release and debug modes.
- need to allow memory to space TAG variables
Best alternative for Logging in Android it's a Timber library. Timber library allow us to write logs just in debug> mode and Timber not required
TAG for logging.
Timber.i("A button with ID %s was clicked to say '%s'.", button.getId(), button.getText());
You can download log from connected device use next command:
adb shell logcat > log.txt<br />