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 – Log.d(TAG, “some message”)
  • ERROR – Log.e(TAG, “some message”)
  • INFO – Log.i(TAG, “some message”)
  • VERBOSE – Log.v(TAG, “some message”)
  • WARN – Log.w(TAG, “some message”)

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:

  1. methods Log.* write logs in release and debug modes.
  2. need to allow memory to space TAG variables

Best alternative for Logging in Android it’s Timber library by Jake Wharton. Timber library allow 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

0 CommentsClose Comments

Leave a comment

Newsletter Subscribe

Get the Latest Posts & Articles in Your Email

We Promise Not to Send Spam:)