記錄:跟同事去測試那現場看log,從終端過濾命令不太熟練
參考連接:https://www.cnblogs.com/zhengah/p/4565624.html
android輸出的每一條日誌都有一個標記和優先級與其關聯。
優先級是下面的字符,順序是從低到高:
V — 明細 verbose(最低優先級)
D — 調試 debug
I — 信息 info
W — 警告 warn
E — 錯誤 error
F — 嚴重錯誤 fatal
S — 無記載 silent
1、只顯示需要的輸出(白名單)
adb logcat | grep CloudSDK
adb logcat | grep "CloudSDK"
adb logcat | grep -i cloudsdk #忽略大小寫。
adb logcat | grep " ..oud" # 省略前倆字符,從第三個字符開始
adb logcat *:E |grep CloudSDK //顯示所有優先級大於等於Error 的日誌
adb logcat *:E |grep -i cloudsdk
adb logcat | grep "I.CloudSDK" //輸出級別爲Info的 tag爲CloudSDK的命令行
adb logcat | grep "E.CloudSDK" //輸出級別爲Error的 tag爲CloudSDK的命令行
adb logcat CloudSDK:E *:S //輸出級別大於等於Error的 tag爲CloudSDK的命令行
//使用 | 分割多個匹配表達式,要加轉義符。例如要匹配 tag 爲 System.err 和 CloudSDK 的輸出:
adb logcat | grep " System.err\| CloudSDK" # \| 爲轉義符
adb logcat | grep -E "System.err|CloudSDK" # 使用 egrep 無須轉義符
//-s: 設置輸出日誌的標籤, 只顯示該標籤的日誌;所有級別的
adb logcat -s CloudSDK
adb logcat -s ActivityManager:I //輸出標記爲“ActivityManager”且優先級大於等於“Info”的日誌
//僅輸出標記爲“ActivityManager”且優先級大於等於“Info”和標記爲“PowerManagerService”並且優先級大於等於“Debug”的日誌:
adb logcat ActivityManager:I PowerManagerService:D *:S
注:*:S用於設置所有標記的日誌優先級爲S,這樣可以確保僅輸出符合條件的日誌。
2、過濾不需要的輸出(黑名單)
還是使用 grep,用法也跟上面的一樣,加一個 -v 即可。例如要過濾 tag 爲 System.err 和 CloudSDK 的輸出:
adb logcat | grep -v "CloudSDK\|System.err"
adb logcat | grep -vE "CloudSDK|System.err"
3、顯示同一個進程的所有輸出
有時一個程序裏面的 tag 有多個,需要輸出該程序(同一個 PID)的所有 tag;僅使用 tag 過濾有時也會漏掉一些錯誤信息,而一般錯誤信息也是和程序同一個 PID。還是通過 grep 實現,思路是先根據包名找到 pid 號,然後匹配 pid。寫成 shell 腳本如下,參數是程序的 java 包名(如 com.android.media)。
#!/bin/bash
packageName=$1
pid=`adb shell ps | grep $packageName | awk ‘{print $2}’`
adb logcat | grep –color=auto $pid
4、從當前開始顯示
logcat 有緩存,如果僅需要查看當前開始的 log,需要清空之前的。
adb logcat -c && adb logcat|grep "CloudSDK"
5、保存日誌到文件
adb logcat > test.log //將日誌保存到文件test.log
adb logcat | grep CloudSDK > test1.log
在window上
C:\Users\xxxxx\Desktop>adb logcat | findStr CloudSDK > test.log
6、可以同時設置多個過濾器
輸出 CloudSDK 標籤 的 Error以上級別 和 System.err 標籤的 warn 以上級別的日誌;
adb logcat CloudSDK:E System.err:W *:S
來源鏈接:https://www.runoob.com/linux/linux-comm-grep.html
Grep命令
Linux grep 命令用於查找文件裏符合條件的字符串。
grep 指令用於查找內容包含指定的範本樣式的文件,如果發現某文件的內容符合所指定的範本樣式,預設 grep 指令會把含有範本樣式的那一列顯示出來。若不指定任何文件名稱,或是所給予的文件名爲 -,則 grep 指令會從標準輸入設備讀取數據。
語法
grep [-abcEFGhHilLnqrsvVwxy][-A<顯示列數>][-B<顯示列數>][-C<顯示列數>][-d<進行動作>][-e<範本樣式>][-f<範本文件>][--help][範本樣式][文件或目錄...]
參數:
-a 或 --text : 不要忽略二進制的數據。
-A<顯示行數> 或 --after-context=<顯示行數> : 除了顯示符合範本樣式的那一列之外,並顯示該行之後的內容。
-b 或 --byte-offset : 在顯示符合樣式的那一行之前,標示出該行第一個字符的編號。
-B<顯示行數> 或 --before-context=<顯示行數> : 除了顯示符合樣式的那一行之外,並顯示該行之前的內容。
-c 或 --count : 計算符合樣式的列數。
-C<顯示行數> 或 --context=<顯示行數>或-<顯示行數> : 除了顯示符合樣式的那一行之外,並顯示該行之前後的內容。
-d <動作> 或 --directories=<動作> : 當指定要查找的是目錄而非文件時,必須使用這項參數,否則grep指令將回報信息並停止動作。
-e<範本樣式> 或 --regexp=<範本樣式> : 指定字符串做爲查找文件內容的樣式。
-E 或 --extended-regexp : 將樣式爲延伸的正則表達式來使用。
-f<規則文件> 或 --file=<規則文件> : 指定規則文件,其內容含有一個或多個規則樣式,讓grep查找符合規則條件的文件內容,格式爲每行一個規則樣式。
-F 或 --fixed-regexp : 將樣式視爲固定字符串的列表。
-G 或 --basic-regexp : 將樣式視爲普通的表示法來使用。
-h 或 --no-filename : 在顯示符合樣式的那一行之前,不標示該行所屬的文件名稱。
-H 或 --with-filename : 在顯示符合樣式的那一行之前,表示該行所屬的文件名稱。
-i 或 --ignore-case : 忽略字符大小寫的差別。
-l 或 --file-with-matches : 列出文件內容符合指定的樣式的文件名稱。
-L 或 --files-without-match : 列出文件內容不符合指定的樣式的文件名稱。
-n 或 --line-number : 在顯示符合樣式的那一行之前,標示出該行的列數編號。
-o 或 --only-matching : 只顯示匹配PATTERN 部分。
-q 或 --quiet或--silent : 不顯示任何信息。
-r 或 --recursive : 此參數的效果和指定"-d recurse"參數相同。
-s 或 --no-messages : 不顯示錯誤信息。
-v 或 --revert-match : 顯示不包含匹配文本的所有行。
-V 或 --version : 顯示版本信息。
-w 或 --word-regexp : 只顯示全字符合的列。
-x --line-regexp : 只顯示全列符合的列。
-y : 此參數的效果和指定"-i"參數相同
參考鏈接:https://blog.csdn.net/lwz622/article/details/84403088
Logcat命令列表:
--"-s"選項 : 設置輸出日誌*:s的標籤, 只顯示該標籤的日誌;
--"-d" 將日誌顯示在控制檯後退出
--"-c" 清理已存在的日誌
--"-f <filename>" 將日誌輸出到文件
adb logcat -f /sdcard/test.txt
-v <format>設置日誌輸入格式控制輸出字段,默認的是brief格式
brief — 顯示優先級/標記和原始進程的PID (默認格式)
process — 僅顯示進程PID
tag — 僅顯示優先級/標記
thread — 僅顯示進程:線程和優先級/標記
raw — 顯示原始的日誌信息,沒有其他的元數據字段
time — 顯示日期,調用時間,優先級/標記,PID
long —顯示所有的元數據字段並且用空行分隔消息內容
adb logcat -v thread //使用 thread 輸出格式
注意-v 選項中只能指定一種格式。
-b <buffer>加載一個可使用的日誌緩衝區供查看,默認值是main。
radio — 查看包含在無線/電話相關的緩衝區消息
events — 查看事件相關的消息
main — 查看主緩衝區 (默認緩衝區)
adb logcat -b radio //查看radio緩衝區
--"-r"選項 : 按照每千字節輸出日誌, 需要 -f 參數, 不過這個命令沒有執行成功;
--"-n"選項 : 設置日誌輸出的最大數目, 需要 -r 參數, 這個執行 感覺 跟 adb logcat 效果一樣;
--"-d"選項 : 將緩存的日誌輸出到屏幕上, 並且不會阻塞;
--"-t"選項 : 輸出最近的幾行日誌, 輸出完退出, 不阻塞;
--"-g"選項 : 查看日誌緩衝區信息;
--"-B"選項 : 以二進制形式輸出日誌;
輸出指定標籤內容 :
– "-s"選項 : 設置默認的過濾器, 如 我們想要輸出 “System.out” 標籤的信息, 就可以使用 adb logcat -s System.out 命令;
octopus@octopus:~$ adb logcat -s System.out
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/System.out(22930): GSM -91
I/System.out(22930): SignalStrength issssssssss : -91
I/System.out(22930): GSM -91
I/System.out(22930): SignalStrength issssssssss : -91
I/System.out(22930): Supervisor Thread
I/System.out(22930): Got run mode
輸出日誌信息到文件 :
– "-f"選項 : 該選向後面跟着輸入日誌的文件, 使用 adb logcat -f log 命令, 會出現錯誤, 這裏我們不推薦使用該選項
octopus@octopus:~$ adb logcat -f log
couldn't open output file: Read-only file system
– ">"輸出 : “>” 後面跟着要輸出的日誌文件, 可以將 logcat 日誌輸出到文件中, 使用 adb logcat > log 命令, 使用 more log 命令查看日誌信息;
octopus@octopus:~$ adb logcat > log
^C
octopus@octopus:~$ more log
--------- beginning of /dev/log/system
V/ActivityManager( 500): We have pending thumbnails: null
V/ActivityManager( 500): getTasks: max=1, flags=0, receiver=null
V/ActivityManager( 500): com.android.settings/.Settings: task=TaskRecord{42392278 #448 A com.android.settings U 0}
V/ActivityManager( 500): We have pending thumbnails: null
指定 logcat 的日誌輸出格式 :
– "-v"選項 : 使用 adb logcat -v time 命令, 可以啥看日誌的輸出時間;
– "brief"格式 : 這是默認的日誌格式 " 優先級 / 標籤 (進程ID) : 日誌信息 ", 使用 adb logcat -v prief 命令;
octopus@octopus:~$ adb logcat -v brief
--------- beginning of /dev/log/system
D/PowerManagerService( 500): handleSandman: canDream=true, mWakefulness=Awake
D/PowerManagerService( 500): releaseWakeLockInternal: lock=1101267696, flags=0x0
– "process"格式 : " 優先級 (進程ID) : 日誌信息 ", 使用 adb logcat -v process 命令;
octopus@octopus:~$ adb logcat -v process
--------- beginning of /dev/log/system
D( 500) MobileDataStateReceiver received: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED_MOBILE [wap] (MobileDataStateTracker)
V( 500) Broadcast: Intent { act=android.intent.action.ANY_DATA_STATE_MOBILE flg=0x10 (has extras) } ordered=true userid=0 (ActivityManager)
D( 500) wap: Intent from SIM 0, current SIM 0, current DataState DISCONNECTED (MobileDataStateTracker)
D( 500) wap: wap setting isAvailable to false (MobileDataStateTracker)
D( 500) wap: Received state=DISCONNECTED, old=DISCONNECTED, reason=dataDetached (MobileDataStateTracker)
D( 500) BDC-Calling finishReceiver: IIntentReceiver=41c46ba0 (ActivityThread)
– “tag"格式 : " 優先級 / 標籤 : 日誌信息”, 使用 adb logcat -v tag 命令;
octopus@octopus:~$ adb logcat -v tag
--------- beginning of /dev/log/system
I/PowerManagerService: setBrightness mButtonLight 0.
D/PowerManagerService: updateScreenStateLocked: mDisplayReady=true, newScreenState=2, mWakefulness=1, mWakeLockSummary=0x1, mUserActivitySummary=0x1, mBootCompleted=true
D/PowerManagerService: handleSandman: canDream=true, mWakefulness=Awake
– "thread"格式 : " 優先級 ( 進程ID : 線程ID) 標籤 : 日誌內容 ", 使用 adb logcat -v tag 命令;
octopus@octopus:~$ adb logcat -v thread
--------- beginning of /dev/log/system
V( 500: 2141) getTasks: max=1, flags=0, receiver=null
V( 500: 2141) com.lewa.launcher/.Launcher: task=TaskRecord{41dccc20 #425 A com.lewa.launcher U 0}
V( 500: 2141) We have pending thumbnails: null
V( 500: 2140) getTasks: max=1, flags=0, receiver=null
– "raw"格式 : 只輸出日誌信息, 不附加任何其他 信息, 如 優先級 標籤等, 使用 adb logcat -v raw 命令;
octopus@octopus:~$ adb logcat -v raw
--------- beginning of /dev/log/system
notifications are enabled for com.kindroid.security
Assigned score=0 to Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])
Native set alarm :Alarm{41e1ca00 type 3 com.kindroid.security}
reset poweroff alarm none
– "time"格式 : "日期 時間 優先級 / 標籤 (進程ID) : 進程名稱 : 日誌信息 " , 使用 adb logcat -v time 命令;
octopus@octopus:~$ adb logcat -v time
--------- beginning of /dev/log/system
04-25 17:18:13.019 V/ActivityManager( 500): Broadcast sticky: Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) } ordered=false userid=-1
04-25 17:18:13.157 V/NotificationService( 500): enqueueNotificationInternal: pkg=com.kindroid.security id=1020 notification=Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])
04-25 17:18:13.158 V/NotificationService( 500): notifications are enabled for com.kindroid.security
04-25 17:18:13.158 V/NotificationService( 500): Assigned score=0 to Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])
04-25 17:18:13.555 V/ActivityManager( 500): getTasks: max=1, flags=0, receiver=null
– "long"格式 : " [ 日期 時間 進程ID : 線程ID 優先級 / 標籤] 日誌信息 ", 輸出以上提到的所有的頭信息, 使用 adb logcat -v long 命令;
octopus@octopus:~$ adb logcat -v long
--------- beginning of /dev/log/system
[ 04-25 17:21:18.118 500:0x2fe V/ActivityManager ]
We have pending thumbnails: null
[ 04-25 17:21:18.696 593:0x251 W/ActivityThread ]
Content provider com.android.providers.telephony.TelephonyProvider already published as telephony
[ 04-25 17:21:19.119 500:0x396 V/ActivityManager ]
getTasks: max=1, flags=0, receiver=null
清空日誌緩存信息 : 使用 adb logcat -c 命令, 可以將之前的日誌信息清空, 重新開始輸出日誌信息;
將緩存日誌輸出 : 使用 adb logcat -d 命令, 輸出命令, 之後推出命令, 不會進行阻塞;
輸出最近的日誌 : 使用 adb logcat -t 5 命令, 可以輸出最近的5行日誌, 並且不會阻塞;
octopus@octopus:~$ adb logcat -t 5
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
W/ADB_SERVICES(10028): adb: unable to open /proc/10028/oom_adj
D/dalvikvm(23292): threadid=11: created from interp
D/dalvikvm(23292): start new thread
D/dalvikvm(23292): threadid=11: notify debugger
D/dalvikvm(23292): threadid=11 (Thread-24538): calling run()
octopus@octopus:~$
查看日誌緩衝區信息 : 使用 adb logcat -g 命令;
octopus@octopus:~$ adb logcat -g
/dev/log/main: ring buffer is 256Kb (255Kb consumed), max entry is 5120b, max payload is 4076b
/dev/log/system: ring buffer is 256Kb (255Kb consumed), max entry is 5120b, max payload is 4076b
octopus@octopus:~$
加載日誌緩衝區 : 使用 adb logcat -b 緩衝區類型 命令;
– Android中的日誌緩衝區 : system緩衝區 - 與系統相關的日誌信息, radio緩衝區 - 廣播電話相關的日誌信息, events緩衝區 - 事件相關的日誌信息, main緩衝區 - 默認的緩衝區;
octopus@octopus:~$ adb logcat -b radio -t 5
D/PHONE (23599): [GeminiDataSubUtil] UAPP_C6-4
D/GSM (23599): [GDCT][simId1]apnType = default
D/GSM (23599): [GDCT][simId1]isDataAllowed: not allowed due to - gprs= 1 - SIM not loaded - desiredPowerState= false
D/GSM (23599): [GDCT][simId1]isDataPossible(default): possible=false isDataAllowed=false apnTypePossible=true apnContextisEnabled=true apnContextState()=IDLE
I/MUXD (23591): [gsm0710muxd] 3426:main(): Frames received/dropped: 18242/0
octopus@octopus:~$
octopus@octopus:~$ adb logcat -b main -t 5
D/NotificationService( 500): notification.sound=null
D/NotificationService( 500): mDmLock=false
I/ATCIJ (16576): Couldn't find 'atci-serv-fw' socket; retrying after timeout
W/ADB_SERVICES( 246): create_local_service_socket() name=shell:export ANDROID_LOG_TAGS="" ; exec logcat -b main -t 5
W/ADB_SERVICES(16815): adb: unable to open /proc/16815/oom_adj
octopus@octopus:~$
octopus@octopus:~$ adb logcat -b system -t 5
D/PowerManagerService( 500): updateScreenStateLocked: mDisplayReady=true, newScreenState=0, mWakefulness=0, mWakeLockSummary=0x1, mUserActivitySummary=0x0, mBootCompleted=true
D/PowerManagerService( 500): handleSandman: canDream=false, mWakefulness=Asleep
V/NotificationService( 500): enqueueNotificationInternal: pkg=com.kindroid.security id=1020 notification=Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])
V/NotificationService( 500): notifications are enabled for com.kindroid.security
V/NotificationService( 500): Assigned score=0 to Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])
octopus@octopus:~$
octopus@octopus:~$ adb logcat -b event -t 5
Unable to open log device '/dev/log/event': No such file or directory
octopus@octopus:~$ adb logcat -b events -t 5
I/notification_cancel( 500): [com.kindroid.security,1026,NULL,0,0,64]
I/notification_enqueue( 500): [com.kindroid.security,1020,NULL,0,Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])]
I/notification_cancel( 500): [com.kindroid.security,1026,NULL,0,0,64]
I/notification_enqueue( 500): [com.kindroid.security,1020,NULL,0,Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])]
I/notification_cancel( 500): [com.kindroid.security,1026,NULL,0,0,64]
octopus@octopus:~$
以二進制形式輸出日誌 : 使用 adb logcat -B 命令;
octopus@octopus:~$ adb logcat -B -t 5
O��_�3ZS�4gps_mt3326nmea_reader_parse: line = 1218GPS get accuracy failed, fix mode:1
^��_�3ZS�=gps_mt3326nmea_reader_addc: line = 1331the structure include nmea_cb address is 0x658cc8e8
H��_�3ZSEGEgps_mt3326nmea_reader_addc: line = 1332nmea_cb address is 0x5d2fe279
i���3ZS�)>ADB_SERVICEScreate_local_service_socket() name=shell:export ANDROID_LOG_TAGS="" ; exec logcat -B -t 5
7*E*E�3ZSo�YADB_SERVICESadb: unable to open /proc/17706/oom_adj
- 過濾項解析
過濾項格式 : [:priority] , 標籤:日誌等級, 默認的日誌過濾項是 " *:I " ;
– V : Verbose (明細);
– D : Debug (調試);
– I : Info (信息);
– W : Warn (警告);
– E : Error (錯誤);
– F : Fatal (嚴重錯誤);
– S : Silent(Super all output) (最高的優先級, 可能不會記載東西);
過濾指定等級日誌 : 使用 adb logcat 10 *:E 命令, 顯示 Error 以上級別的日誌;
octopus@octopus:~$ adb logcat *:E
Note: log switch off, only log_main and log_events will have logs!
--------- beginning of /dev/log/main
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/dalvikvm( 756): GC_CONCURRENT freed 1809K, 27% free 19489K/26695K, paused 16ms+5ms, total 109ms
E/WifiHW ( 441): wifi_send_command : SCAN ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/dalvikvm( 756): GC_CONCURRENT freed 1820K, 27% free 19490K/26695K, paused 16ms+3ms, total 102ms
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
過濾指定標籤等級日誌 : 使用 adb logcat WifiHW:D *:S 命令進行過濾;
– 命令含義 : 輸出10條日誌, 日誌是 標籤爲 WifiHW, 並且優先級 Debug(調試) 等級以上的級別的日誌;
– 注意 *:S : 如果沒有 *S 就會輸出錯誤;
octopus@octopus:~$ adb logcat WifiHW:D *:S
Note: log switch off, only log_main and log_events will have logs!
--------- beginning of /dev/log/main
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
可以同時設置多個過濾器 : 使用 adb logcat WifiHW:D dalvikvm:I *:S 命令, 輸出 WifiHW 標籤 的 Debug 以上級別 和 dalvikvm 標籤的 Info 以上級別的日誌;
octopus@octopus:~$ adb logcat WifiHW:D dalvikvm:I *:S
Note: log switch off, only log_main and log_events will have logs!
--------- beginning of /dev/log/main
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/dalvikvm( 756): GC_CONCURRENT freed 1820K, 27% free 19490K/26695K, paused 17ms+2ms, total 110ms
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/dalvikvm( 756): GC_CONCURRENT freed 1810K, 27% free 19489K/26695K, paused 17ms+5ms, total 108ms
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
- 使用管道過濾日誌
(1) 過濾固定字符串
過濾固定字符串 : 只要命令行出現的日誌都可以過濾, 不管是不是標籤;
– 命令 : adb logcat | grep Wifi ;
octopus@octopus:~$ adb logcat | grep Wifi
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
過濾字符串忽略大小寫 : adb logcat | grep -i wifi ;
(2) 使用正則表達式匹配
分析日誌 : 該日誌開頭兩個字符是 “V/”, 後面開始就是標籤, 寫一個正則表達式 “^…ActivityManager”, 就可以匹配日誌中的 “V/ActivityManager” 字符串;
V/ActivityManager( 574): getTasks: max=1, flags=0, receiver=null
正則表達式過濾日誌 : 使用上面的正則表達式組成命令 adb logcat | grep “^…Activity” ;