Android crash log using ADB over command line
Filter logs in bash using ADB (android debug bridge) in any bash.
Start with ADB manual,
ADB manual
$ adb logcat --help
Show all adb logs
$ adb logcat---- OUTPUT ---
com.customapp.aasaservice/1000 (adj 906): empty #3107-03 15:44:53.532 1489 1512 W libocessgroup: kill(-16466, 9) failed: No such process
07-03 15:44:53.565 1489 1512 I chatty : uid=1000(system) ActivityManager identical 5 lines
07-03 15:44:53.571 1489 1512 W libpressgroup: kill(-16466, 9) failed: No such process
...
...
...
Filter logs by Tag name i.e. `MainActivity`
$ adb logcat -s MainActivity---- OUTPUT ---07-03 16:00:09.005 16089 16089 D MainActivity: MainActivity.kt:10 - starting my page
07-03 16:00:19.005 16089 16089 D MainActivity: MainActivity.kt:20 - finishing my page
...
...
...
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---- OUTPUT ---MainActivity.kt:10 - starting my page
MainActivity.kt:49 - showPopup() is called
MainActivity.kt:20 - finishing my page
...
...
...
I prefer to see TAG and Priority info as well using below command,
$ adb logcat -s MainActivity -v tag---- OUTPUT ---V/MainActivity: MainActivity.kt:10 - starting my page
D/MainActivity: MainActivity.kt:49 - showPopup() is called
V/MainActivity: MainActivity.kt:20 - finishing my page
...
...
...
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---- OUTPUT ---07-03 16:44:25.836 20096 20096 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property mWebView has not been initialized07-03 16:44:25.836 20096 20096 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
...
...
...
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*”---- OUTPUT ---
V/MxMainActivity: MainActivity.kt:10 - starting my page
D/MxMainActivity: MainActivity.kt:49 - showPopup() is called
V/MxVideoDownloader: MxVideoDownloader.kt:12 - download started
V/MxAudioDownloader: MxAudioDownloader.kt:25 - finishing my page$ adb logcat -v tag | grep -e “^V.Mx.*.Downloader”---- OUTPUT --
V/MxVideoDownloader: MxVideoDownloader.kt:12 - download started
V/MxAudioDownloader: MxAudioDownloader.kt:25 - finishing my page
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”---- OUTPUT --
W/libprocessgroup: kill(-29662, 9) failed: No such processW/libprocessgroup: kill(-29662, 9) failed: No such processW/libprocessgroup: kill(-29662, 9) failed: No such
....
....
....
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
Post a Comment