Android crash log using ADB over command line

Filter logs in bash using ADB (android debug bridge) in any bash.

S
tart with ADB manual,

ADB manual

$ adb logcat --help

Show all adb logs

$ adb logcat

Filter logs by Tag name i.e. `MainActivity`

$ adb logcat -s MainActivity

Exclude metadata info from logs

In most of the time as a developer you don’t need to see the meta info concatenated prior to each log line i.e, datetime, pid, tag, priority etc. which sometimes takes unnecessary space. You can ignore them if you want,

$ adb logcat -s MainActivity -v raw

I prefer to see TAG and Priority info as well using below command,

$ adb logcat -s MainActivity -v tag

Instead of raw you can use brief, long, process, tag, thread, threadtime etc. with -v if you want to customize based on metadata you are interested or not.

Filter based on log priority

We can filter logs by priorities. Each log has a log priority which is a level to represent the importance of the log. There are several priority i.c. verbose, info, debug, warning, error, fatal, silent. We can use filter with priority like,

$ adb logcat -s MainActivity:D -v tag  #for debugs logs only

The above command filters the logs and shows only the logs which have priority level debug and above under the tag MainActivity.

Filter based on the buffer (main, radio, crash)

One way to get the crash logs is filtering with -b crash. main, system, radio, and crash can be used to filter with -b.

$ adb logcat -b crash

Apply regex on the tag name

When you want to see all logs whose tag name matches with a regex pattern. For example, we usually start tag name with applications or modules preset prefix. Let’s say my application prefix is Mx, so all my class and tags names usually start with Mx, i.e. MxMainActivity, MxPrefActivity etc. On the other hand MxAudioDownloader, MxVideoDownloader might be other tags. We can easily apply regex on to tag name like,

$ adb logcat -v tag | grep -e “^..Mx*”

Apply regex on log text

We can easily filter logs by applying regex on to the log messages as well

$ adb logcat -v tag | grep -e “failed”

Exclude regex on to log tag or log text

We often need to hide system, framework, viewport etc. related unnecessary logs. That can be done using,

$ adb logcat -v tag | grep -E --invert-match “WifiTrafficPoller” #OR
$ adb logcat -v tag | grep -E -v “WifiTrafficPoller”

show Colorful regex matched text

$ adb logcat -v tag | grep -e “failed” --color=auto -i 

Clearing current buffer

$ adb logcat -c

Comments

Popular Posts