Bin Chen
Bin Chen

Reputation: 63289

how to monitor android adb logcat and do a grep?

I have an application that can print some logs into android log system, it has some keywords that I want to monitor, what I want to achieve is:

Monitor "adb logcat" output, if there is a new line contains the keyword, print out the new line.

It's something like adb logcat | grep "command" but as you know adb logcat will block there so my grep can't see any input. Is it doable using simple shell script?

Upvotes: 1

Views: 26520

Answers (3)

pukingminion
pukingminion

Reputation: 117

To view logcat for a particular process :

 adb logcat | grep <process_id>

To view logcat for a particular process with the tag name too :

 adb logcat | grep <process_id> | grep -s "TAG NAME"

| acts as a separator for combining different queries.

Upvotes: 3

CoDe
CoDe

Reputation: 11146

you can try in following manner

log_1=$(adb shell dumpsys meminfo com.azoi.azoitv | grep Views:) 
echo $log_1

if you want to perform in continuous loop, u can try this:

while :
do
    log_1=$(adb shell dumpsys meminfo com.azoi.azoitv | grep Views:)
    echo  $log_1
done

Upvotes: 0

Femi
Femi

Reputation: 64690

If you look at http://developer.android.com/guide/developing/tools/adb.html, in the section titled Filtering Log Output, this describes adb's native filtering capabilities. This will probably work for you. You can specify a specific tag in your log statements (which would essentially be whatever you would have sent to bash) and then just filter on those tags. For example:

android.util.Log.v("filter1","<this is my log statement>");

would be the code, and you'd then do

adb logcat filter1:V

to filter for that output.

EDIT: you can always use this to dump to a file, and then run bash on that.

Upvotes: 6

Related Questions