Navigating the Depths of Android Logcat¶
Advanced Logcat Commands¶
All commands/scripts in this section is done by Patrik Gissleholm
and is under MIT License
Highlight Specific String in adb logcat Output Using Custom Colors
HIglight specifik strings in adb logcat Output Using Custom Colors
Logcat application by pid
Printing Log Entries Related to Lock Settings
Hilight Matched Lines by Red Backgrond
Create SubSettings Commands
Create adb shell commands for received broadcasts
adb logcat | awk '
/Received BROADCAST.*SCREEN_ON/ {
match($0, /pkg=[^ ]+/, pkgArr)
match($0, /act=[^ ]+/, actArr)
match($0, /cmp=[^ ]+/, cmpArr)
if (pkgArr[0] && actArr[0] && cmpArr[0]) {
pkg = substr(pkgArr[0], 5)
act = substr(actArr[0], 5)
cmp = substr(cmpArr[0], 5)
printf "adb shell am broadcast -a \033[1;33m'%s'\033[0m -n \033[1;36m'%s'\033[0m\n", act, cmp
}
}'
Custom Timestamp Format for adb logcat
Colorize specifik tags and field 5
adb logcat | awk '/(SyntheticPasswordManager|SyntheticPasswordCrypto|ResumeOnRebootServiceProvider|RebootEscrowProviderServerBased|RebootEscrowProviderHal|RebootEscrowManager| RebootEscrowKeyStoreManager|PasswordSlotManager|ManagedProfilePasswordCache|LockSettings|LockSettingsDB|LockSettingsStorage|LockSettingsService|BiometricDeferredQueue)/ {
if ($5 == "V")
$5 = "\033[36m" $5 "\033[0m"
else if ($5 == "D")
$5 = "\033[34m" $5 "\033[0m"
else if ($5 == "I")
$5 = "\033[32m" $5 "\033[0m"
else if ($5 == "W")
$5 = "\033[33m" $5 "\033[0m"
else if ($5 == "E")
$5 = "\033[31m" $5 "\033[0m"
else if ($5 == "F")
$5 = "\033[31;1m" $5 "\033[0m"
else if ($5 == "S")
$5 = "\033[35m" $5 "\033[0m"
if ($6 == "DEBUG")
$6 = "\033[32m" $6 "\033[0m"
else if ($6 == "INFO")
$6 = "\033[35m" $6 "\033[0m"
else if ($6 == "WARN")
$6 = "\033[33m" $6 "\033[0m"
else if ($6 == "ERROR")
$6 = "\033[31m" $6 "\033[0m"
print
}'
This command colors all the activities in red
Colrorize tags + verbose same color entire line (different for each)
adb logcat -s 'SyntheticPasswordManager' 'SyntheticPasswordCrypto' 'ResumeOnRebootServiceProvider' 'RebootEscrowProviderServerBased' 'RebootEscrowProviderHal' 'RebootEscrowManager' 'RebootEscrowKeyStoreManager' 'PasswordSlotManager' 'ManagedProfilePasswordCache' 'LockSettings' 'LockSettingsDB' 'LockSettingsStorage' 'LockSettingsService' 'BiometricDeferredQueue' | awk '{if (($5 in seen) || ($6 in seen)) printf "\033[1;31m%s\033[0m\n", $0; else seen[$5]; seen[$6]}'
Colrorize tags + verbose same color column 5 and 6
adb logcat -s 'SyntheticPasswordManager' 'SyntheticPasswordCrypto' 'ResumeOnRebootServiceProvider' 'RebootEscrowProviderServerBased' 'RebootEscrowProviderHal' 'RebootEscrowManager' 'RebootEscrowKeyStoreManager' 'PasswordSlotManager' 'ManagedProfilePasswordCache' 'LockSettings' 'LockSettingsDB' 'LockSettingsStorage' 'LockSettingsService' 'BiometricDeferredQueue' | awk '{for( i=1; i<=NF; i++) {if ((i==5 || i==6) && ($i in seen)) $i="\033[1;31m"$i"\033[0m"; else if (i==5 || i==6) seen[$i]++;} print}'
Mixing logcat and color
adb logcat -v brief -v color 'AppOps' 'SyntheticPasswordManager' 'SyntheticPasswordCrypto' 'ResumeOnRebootServiceProvider' 'RebootEscrowProviderServerBased' 'RebootEscrowProviderHal' 'RebootEscrowManager' 'RebootEscrowKeyStoreManager' 'PasswordSlotManager' 'ManagedProfilePasswordCache' 'LockSettings' 'LockSettingsDB' 'LockSettingsStorage' 'LockSettingsService' 'BiometricDeferredQueue' | awk '{for(i=1; i<=NF; i++) {if (i==5 && ($i in seen)) $i="\033[1;31m"$i"\033[0m"; else if (i==5) seen[$i]++;} print}'
Colorize Only Info Levels (Field 5)
adb logcat | awk '{
if ($5 == "V")
$5 = "\033[36m" $5 "\033[0m"
else if ($5 == "D")
$5 = "\033[34m" $5 "\033[0m"
else if ($5 == "I")
$5 = "\033[32m" $5 "\033[0m"
else if ($5 == "W")
$5 = "\033[33m" $5 "\033[0m"
else if ($5 == "E")
$5 = "\033[31m" $5 "\033[0m"
else if ($5 == "F")
$5 = "\033[31;1m" $5 "\033[0m"
else if ($5 == "S")
$5 = "\033[35m" $5 "\033[0m"
print
}'
Colorize Every Column
Colorize Output to Rainbow
Colorize output to Rainbow colors
Generate activity commands for adb
Start logcat in the background and redirect output to a pipe for callback services
Monitor WindowManager and create am start commands
Find Activities for Currently Running Applications (follow activities)
adb logcat | awk '
/act=android.intent.action.MAIN/ && /cmp=/ {
match($0, /act=[^ ]+/);
act=substr($0, RSTART+4, RLENGTH-4);
match($0, /cmp=[^ ]+/);
cmp=substr($0, RSTART+4, RLENGTH-4);
printf "adb shell am start -a '\''";
printf "\033[38;5;202m" act "\033[0m";
printf "'\'' -n '\''";
printf "\033[38;5;46m" cmp "\033[0m";
print "'\''"
}'
Find Services for Currently Running Applications (follow services)
Find Broadcast Receiver for Currently Running Applications (follow services)
Grep all services that can be launched with activity manager
Grep all broadcasts
Randomize Colors for Each Field
Randomize Colors for Each Field (Extended Range)
Highlight 6th Field with Red
Highlight Lines Containing 'Wifi' with Red
Highlight all lines with red color before =
and green behind
Highlight Key-Value Pairs with Red and Green
Highlight Lines Containing Specific Text
Highlight Lines Containing 'Permission Denied'
Highlight Lines with Specific Component Names
Highlight Every 5th Field with Blue if it match D
Add Custom Timestamp format to logcat Entries
Highlight First Field with Red color
Highlight Last Field with Red color
Capturing PACMAN Data
adb shell 'su -c logcat \
bt_userial_vendor:I \
BCService:E \
PACMService:I \
PACMSOCKET:D \
PACMClassifier:I \
PACMAN:I \
DataRouter:D \
CSSVC_USB:W \
FsCrypt:D \
UserDataPreparer:D \
FsCrypt:D \
CSSVC_USB:W \
System.err:W \
SatsServiceData:I \
ReactiveService:I \
ziparchive:W \
SamsungAnalytics200003:D \
keystore2:E \
RestrictionPolicy:D \
bt_userial_vendor:I \
coex_device:I \
nativeloader:D \
engmode_java_manager:I \
engmode_jni:I \
engmode_client_list:I \
engmode_steady:I \
engmode_world:I \
engmode_binder_server:I \
engmode_hidl_service:E \
HYPER-HAL:I \
KeySyncTask:D \
DeviceAdminInfo:W \
Watchdog:E \
DARUtil:D \
SDPLog:I \
SDPLog:D \
LockSettingsService:D \
hermesd:I \
SyntheticPasswordManager:D \
STAR_HAL:I \
keymaster_tee:W \
LockSettingsLog:I \
EnterpriseDeviceManagerService:D \
KeyguardSecAbsKeyInputViewController:D \
KeyguardViewBase:D \
keystore2:* \
*:S' | tee at-commanddds.log