Logging

As we have seen in many listings already, you can use the Log class to print out messages to LogCat. In addition to the Java traditional logging mechanism such as System.out.println(), Android defines six log levels, each having its own methods:

  • verbose (Log.v)
  • debug (Log.d)
  • info (Log.i)
  • warning (Log.w)
  • error (Log.e)
  • assert (Log.wtf)

For example, a call to Log.v(TAG, “my message”) is equivalent to a call to Log.println(Log.VERBOSE, TAG, “my message”).

NOTE: The Log.wtf() methods were introduced in API level 8, but Log.ASSERT exists since API level 1. If you want to use the ASSERT log level but want to guarantee compatibility with older Android devices, use Log.println(Log.ASSERT, …) instead of Log.wtf(…).

You can then use LogCat in ...

Get Pro Android Apps Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.