Sunday, June 14, 2009

Android logs with ADT (LogCat)

The LogCat view is on by default in the Debug perspective. I noticed that even when I'm not debugging the view is getting updates from the application running in the emulator. I added the LogCat view to my Java perspective so I can see it anytime.

In the clip above, you can see that the LogCat view defaults in with the Problems, Console, and other views in the bottom-right. I like it there. The second column in the view shows the logging level; this level comes from the method called on the Log object. Here are the clips from my code that correspond to the 'I' messages.

Log.i("ListBuckets", "Setting up grid.");
GridView g = (GridView) findViewById(;
g.setAdapter(new ImageAdapter(this, mBucketsDb.fetchAllBuckets()));

Above, I used just a plain string for the 'tag'; this seems like the common approach in the Android sample code. Below, I went to my more normal use of using the class as the tag.

public void onCreate(SQLiteDatabase db) {
Log.i(BucketsDbAdapter.class.toString(), "Creating fresh database.");

To add the LogCat view to the Java perspective:
1. open the workspace that houses your projects
2. Window -> Show View -> Other...
3. expand the Android tree node and select LogCat


Freek said...

Just what I was looking for, thanks!

MrTidy OTR said...

Adrian Vintu posted a comment but I accidentally deleted it. Here is the contents from the comment. Very cool stuff:

Here is a tool to enhance your logcat experience
Windows link
Linux link


Adrian Vintu

developmentality said...

Very useful info about adding LogCat to your Java perspective. Thanks