adb logcat查看某個進程的輸出日誌

adb logcat 默認是沒有這個功能的,我實現了一個小bash函數,添加到你$HOME/.bashrc 文件中:android

# 做用:可以經過進程名顯示log
# 用法:alogcat com.android.calendar or alogcat calendar
# 當監控的進程異常退出時,須要從新運行此命令
function alogcat() {
	OUT=$(adb shell ps | grep -i $1 | awk '{print $2}')
	OUT=$(echo $OUT | sed 's/[[:blank:]]\+/\|/g')
	# 當進程異常退出,log是經過 AndroidRuntime 輸出的
	adb logcat -v time  |grep -E "$OUT|AndroidRuntime"
}

調用方法:shell

alogcat email

email 替換成你的packagename,全名或部分均可以bash

相關文章
相關標籤/搜索