Wednesday, December 19, 2012

Filter logcat Output by Tag Names

When debugging on android development, sometimes it is hard to find what we need when there are too much data displays on logcat. Most of the time when I do debugging on android, I use the terminal. It's pretty fast and I find it more comfortable than the logcat from Eclipse android plugin. Sometimes I missed out important data because there are unnecessary information displayed on logcat. So what I do is to save the logcat into a file and check it into a browser. This is time consuming though you have all the information. One way to sort out this problem is to filter logcat. adb logcat command has the option to filter your tags that you define in your application. In your code, you might have something similar like this:
private static final String TAG = "Fragment01";
Log.d(TAG, "getUserVisibleHint=" + getUserVisibleHint());
To display "Fragment01" in logcat,
$ adb logcat -s "Fragment01"
But this information isn't enough. What if you also need to see the values of fragment 2? or fragment 3? and etc.? Run this command.
$ adb logcat -s "Fragment01" "Fragment02" "Fragment03"
By adding the tag names on the command this will allow adb to filter it and display in logcat. Do you have some ideas similar to this? Glad if you could share. Let me know your thoughts.