Tuesday, April 13, 2010

Logcat, Improved.

Logcat is a staple for most Android developers out there and I'm certainly no exception. I often have at least one terminal dedicated to logcat with sometimes many more with various combinations of options to control how I'm filtering the output.

Recently it occurred to me that most of this work is designed to separate my program from the noise of the entire platform. The numeric argument printed after the tag in the logcat output is the pid responsible for that log line which I had used in the past to do this sort of filtering but it was a pain when the app crashed or was reinstalled because the pid would change.

Enter my proclogcat script. This script tracks the pid as the process is killed and restarted and takes care of automating the adb shell ps | grep <process> logic on first launch. The best part is the script can be combined with Jeffrey Sharkey's excellent coloredlogcat script (or my modified version of it) for beautiful results.



Download: proclogcat

To use, simply copy it somewhere in your PATH and invoke either manually as adb logcat | proclogcat <process> or in a function as is discussed in the script source code.

5 comments:

biAji said...

Well Done!!

It will be better if I can use pid as argument instead of process name.

^_^

Unknown said...

Excellent work.

Yuku said...

Thanks so much! I've used this for 2 months+!

One improvement will be to support more than one pid for the specified package name. One application can have multiple process as defined in the "process" attribute in the AndroidManifest.xml.

Unknown said...

Has anyone updated this script to accept 'adb logcat -v ' parameters? I'll contribute if it hasn't already been done.

Unknown said...

@yaku, this isn't a use case I encounter often, but I'd happily accept a patch :)