[android] Filter LogCat to get only the messages from My Application in Android?

Update May 17

It's been a few years, and thing have changed. And Eclipse is no longer officially supported. So here's two more up-to-date approaches:

1. Android Studio

enter image description here In the Android monitor toolbox, you can filter logcat per debuggable process. Normally, when you develop an application it is a debuggable process. Every once in a while I am having issues with this, and a do the following:

  1. Tools -> Android -> Enable ADB Integration.
    If it was already enabled, then toggle it off, and then back on

  2. Unplug and replug your mobile device.

There are also options to filter via regex and the debug level

2. logcat-color

This is a nice python wrapper on top of adb logcat if you want to use a terminal based solution. The good thing about it is that you can save multiple configurations and simply reuse them. Filtering by tags is quite reliable. You can also filter by package to see logs of one or more apps only, but you start logcat-color right before launching your app.

Old Answer:

It seems that I can't comment to previous answers, so I will post a new one. This is a comment to Tom Mulcahy's answer, that shows how the command should change so as to work on most devices, since adb shell ps PID column is variable.

NOTE: The command below works for the cases where you have connected many devices. So device id is needed. Otherwise, you can simply omit the brackets '[', ']'

1. To find out the column of pid, type:

adb [-s DEVICE_ID] shell ps | head -n 1

Now memorise the column number for the PID. Numbering starts from 1.

2. Then type the following:

adb [-s DEVICE_ID] logcat | grep $(adb [-s DEVICE_ID] shell ps \
| grep "com.example" | awk -F" " ' {print $PUT_COLUMN_HERE}')

Simply put the column you memorised in PUT_COLUMN_HERE, e.g. $5

Caveat

Each time you re-run your application, you have to re-run the 2nd command, because the application gets a new PID from the OS.