Logcat

Logging in Android

Alex Zhukovich 1 min read
Logging in Android
Table of Contents

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:

  • ASSERT
  • DEBUG - Log.d(TAG, "message")
  • ERROR - Log.e(TAG, "message")
  • INFO - Log.i(TAG, "message")
  • VERBOSE - Log.v(TAG, "message")
  • WARN - Log.w(TAG, "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:

  • methods 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

Mobile development with Alex

A blog about Android development & testing, Best Practices, Tips and Tricks

Share
More from Mobile development with Alex

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Mobile development with Alex.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.