Android error logging examples and Log class documentation

Android error logging FAQ: How do I log error messages in Android?

To log Android errors, just use the Log class, as shown in this example:

package foo;

import android.util.Log;

class Bar {

  private static final String TAG = "EntityListActivity";

  public void foo()
    DatabaseInstaller dbInstaller = new DatabaseInstaller(this);
      Log.i(TAG, "trying to createDatabase ...");
    catch (IOException e)
      // display a message to the user here
      Log.e(TAG, e.getLocalizedMessage());

As you can see from that example, you just call the static methods on the Log class to log your messages. The static methods available all consist of one letter:

  • v - VERBOSE
  • d - DEBUG
  • i - INFO
  • w - WARN
  • e - ERROR

Here's a quick extract from the Android Log class documentation that explains how these methods work, and should be used:

Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e() methods.

The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.

For more information on Android error logging, see the Android Log class documentation.