Tuesday, October 6, 2020

Android Logcat

 Android studio 过滤log中指定字符(不显示包含指定字符的log)

^(?!.*(你要过滤掉的字符)).*$

*log中包含got 或Activity 的log将不显示在控制台。

^(?!.*(got|Activity)).*$


只显示指定字符的log

^(.*(10:30|10:33)).*$

Logcat


採用grep正則表示式過濾

adb logcat | grep -iE "Audio3DSettings|setParameters|setAudio3DState"


在同時輸出到螢幕和檔案 tee

adb logcat | grep -E '^[VDE]/(TAG1|TAG2)' | tee my.log


可以看出 tag 是一行開頭的第三個字元開始

adb logcat | grep "^..MyApp"


僅顯示 Error 級別 tag 為 MyApp 的輸出

adb logcat | grep "^E.MyApp"


要匹配 tag 為 MyApp 和 MyActivity 的輸出

adb logcat | grep "^..MyApp\|^..MyActivity"

adb logcat | grep -E "^..MyApp|^..MyActivity"  #使用 egrep 無須轉義符


過濾 tag 為 MyApp 和 MyActivity 的輸出

adb logcat | grep -v "^..MyApp\|^..MyActivity" 

adb logcat | grep -vE "^..MyApp|^..MyActivity"  #使用 egrep 無須轉義符

logcat | grep -vE "BluetoothAdapter|chatty| BluetoothManagerService| *bluetooth* | *Bluetooth*|bluetoot|bt_*"

顯示同一個程序的所有輸出

#!/bin/bash

packageName=$1 

pid=`adb shell ps | grep $packageName | awk ‘{print $2}’` 

adb logcat | grep –color=auto $pid


從當前開始顯示

adb logcat -c && adb logcat

logcat | grep -e Controller -e StateDvrPlayback

grep 指令使用 or 及 and 查兩個條件以上

No comments:

Post a Comment

n8n index

 【n8n免費本地端部署】Windows版|程式安裝x指令大補帖  【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能