Logging Application Information

Android provides a useful logging utility class called android.util.Log. Logging messages are categorized by severity (and verbosity), with errors being the most severe. Table 3.3 lists some commonly used logging methods of the Log class.

TABLE 3.3 Commonly Used Log Methods




Logs errors


Logs warnings


Logs informational messages


Logs debug messages


Logs verbose messages


The first parameter of each Log method is a string called a tag. One common Android programming practice is to define a global static string to represent the overall application or the specific activity within the application such that log filters can be created to limit the log output to specific data.

For example, you could define a string called TAG, as follows: private static final String TAG = "MyApp";

Now anytime you use a Log method, you supply this tag. An informational logging message might look like this:

Log.¿(TAG, "In onCreate() callback method");

Excessive use of the Log utility can result in decreased application performance. Debug and verbose logging should be used only for development purposes and removed before application publication.

You can use the LogCat utility from within Eclipse to filter your log messages to the tag string. See Appendix B, "Eclipse IDE Tips and Tricks," for details.

Did you Know?

Was this article helpful?

0 0

Post a comment