Last Updated: February 25, 2016
· jaymzcd

Create list of hardcoded tags for logcat filter-spec

Sometimes if you're taking over a project you might find your source files have tags for debugging scattered throughout rather than in static strings. It's useful when getting an understanding of what the app is doing to add traces throughout. The unfiltered output from logcat can often be overwhelming.

Using bash to match log lines in java files then awk to output the first bit of the string and then sorting and passing to xargs to format on a line makes it easy when opening a new project:

function android_tags {
    # Gets the list of unique tags in a project for logcat filterspecs
    grep Log\. -r --include "*.java" | awk -F\" '{print $2}' | sort -u | xargs

adb -d logcat -s `android_tags`

For example:

[18:00][wario][jaymz][app][master]$ android_tags 
APITest Colors DetailsTask FilterTask HomeActivity SearchTask

[18:02][wario][jaymz][app][master]$     adb -d logcat -s `android_tags`
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/ClearCacheService( 3594): Cleaning cache...
D/ClearCacheService( 3594): Cleaning cache DONE
D/HomeActivity( 3594): 404 -> Exception, url: null, json: null

1 Response
Add your response

Actually, once you start any refactoring maybe take a look at Gonçalo Silva's tip of using the class name automatically:

over 1 year ago ·