Wednesday, February 12, 2014

Colored Logcat on Android

A fast hack done many moons ago to get logcat running over adb in color on an Android device. Posted for prosperity.


COLOR LOGCAT

Many moons ago, +Jeff Sharkey posted a python script to colour (or even color) in the output according to error severity etc...

And it was good.





PYTHON 2.6

At some point when hacking away for some project or other, I cross compiled python to ARM v5 (at the time, the default ARM architecture for Android) and statically linked it against gcc, I assume so it could run on a busybox based initramfs (but it was a long time ago and I was in China at the time drunk on jetlag). I fell across the code again and decided to see if it runs on my latest Android phone.

Poking at the code, it seems I stripped a lot of support libraries from the 2.7 release (the .py files) so it would take up less disk space (originally it was installed on the system disk of a development device). However, these files are pretty quick to restore if required from the python distribution.

Python was super handy when scripting power management tests i.e. grabbing the contents of /proc/stat and comparing against the behavior of the CPU governor.


CLOGCAT

Here is the code that you can extract / push to an Android device and experience the joy of color logcat over a serial cable. I quickly butchered it so it runs from /data instead of the system disk.
cd <extracted directory>
adb push clogcat-rev3 /data/local/tmp
adb shell
cd /data/local/tmp
./setup_clogcat.sh
./clogcat.sh <normal logcat parameters>

I recall in the past installing an Android terminal emulator APK and running clogcat from a shell, more to see what it did performance wise than anything. It was pretty sweet even on 2009 era SoCs (the good old days!).


RETROSPECTIVE

I suspect that adding in a little color to logcat would have been achieved much quicker by editing the src to the logcat app and inserting code that sends terminal colors commands in between the various log prints.

#define RED_ON "\033[0;31m"
#define RED_OFF WHITE_ON

#define YELLOW_ON "\033[0;33m"
#define YELLOW_OFF WHITE_ON

printf( RED_ON "All the errors!\n", RED_OFF );

No comments:

Post a Comment