Logcat real-time monitoring and notify on assert

1.3k views Asked by At

When developing on Android, I sometimes miss some asserts in the console (logcat), so I would like to be notified whenever an "Assert" message comes in the logcat, with a "growl" notification for example (I'm on Mac OS X).

I tried this simple command:

adb logcat | grep Assert | growlnotify

but it does not send any notification until I kill the logcat process.

Any ideas?

1

There are 1 answers

0
dbernard On BEST ANSWER

OK I have been able to make it work, but I had to use an external script:

growl-on-assert.sh

#!/bin/bash
while read; do
    COUNT=`echo "$REPLY" | grep -c Assert`
    if [ $COUNT -ne 0 ]; then
        echo "$REPLY" | growlnotify -t "Assert on logcat"
    fi
done

And then launching the monitoring with this one-liner in the console:

while [ 1 ]; do adb logcat -sv time *:E | growl-on-assert.sh; done

The infinite loop is useful so adb can reconnect automatically when the device is connected/disconnected.

Any improvements are welcome, for example launching parallels monitoring where there are more than one device/simulator connected at the same time, or sending an email instead of a growl notification. ;-)