adb logcat 命令詳解 log過濾

eclipse 自帶的 LogCat 工具太垃圾了, 開始用 adb logcat 在終端查看日志;

<a name="t0" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a><a target="_blank" name="t0" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>1. 解析 adb logcat 的幫助信息

在命令行中輸入 adb logcat --help 命令, 就可以顯示該命令的幫助信息;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat --help

  2. Usage: logcat [options] [filterspecs]

  3. options include:

  4. -s Set default filter to silent.

  5. Like specifying filterspec '*:s'

  6. -f <filename> Log to file. Default to stdout

  7. -r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f

  8. -n <count> Sets max number of rotated logs to <count>, default 4

  9. -v <format> Sets the log print format, where <format> is one of:

  10. brief process tag thread raw time threadtime long

  11. -c clear (flush) the entire log and exit

  12. -d dump the log and then exit (don't block)

  13. -t <count> print only the most recent <count> lines (implies -d)

  14. -g get the size of the log's ring buffer and exit

  15. -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio'

  16. or 'events'. Multiple -b parameters are allowed and the

  17. results are interleaved. The default is -b main -b system.

  18. -B output the log in binary

  19. filterspecs are a series of

  20. <tag>[:priority]

  21. where <tag> is a log component tag (or * for all) and priority is:

  22. V Verbose

  23. D Debug

  24. I Info

  25. W Warn

  26. E Error

  27. F Fatal

  28. S Silent (supress all output)

  29. '' means ':d' and <tag> by itself means <tag>:v

  30. If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.

  31. If no filterspec is found, filter defaults to '*:I'

  32. If not specified with -v, format is set from ANDROID_PRINTF_LOG

  33. or defaults to "brief"

adb logcat 命令格式 : adb logcat [選項(xiàng)] [過濾項(xiàng)], 其中 選項(xiàng) 和 過濾項(xiàng) 在 中括號(hào) [] 中, 說明這是可選的;

<a name="t1" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a><a target="_blank" name="t1" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>(1) 選項(xiàng)解析

選項(xiàng)解析 :

-- "-s"選項(xiàng) : 設(shè)置輸出日志的標(biāo)簽, 只顯示該標(biāo)簽的日志;

-- "-f"選項(xiàng) : 將日志輸出到文件, 默認(rèn)輸出到標(biāo)準(zhǔn)輸出流中, -f 參數(shù)執(zhí)行不成功;

-- "-r"選項(xiàng) : 按照每千字節(jié)輸出日志, 需要 -f 參數(shù), 不過這個(gè)命令沒有執(zhí)行成功;

-- "-n"選項(xiàng) : 設(shè)置日志輸出的最大數(shù)目, 需要 -r 參數(shù), 這個(gè)執(zhí)行 感覺 跟 adb logcat 效果一樣;

-- "-v"選項(xiàng) : 設(shè)置日志的輸出格式, 注意只能設(shè)置一項(xiàng);

-- "-c"選項(xiàng) : 清空所有的日志緩存信息;

-- "-d"選項(xiàng) : 將緩存的日志輸出到屏幕上, 并且不會(huì)阻塞;

-- "-t"選項(xiàng) : 輸出最近的幾行日志, 輸出完退出, 不阻塞;

-- "-g"選項(xiàng) : 查看日志緩沖區(qū)信息;

-- "-b"選項(xiàng) : 加載一個(gè)日志緩沖區(qū), 默認(rèn)是 main, 下面詳解;

-- "-B"選項(xiàng) : 以二進(jìn)制形式輸出日志;

.

輸出指定標(biāo)簽內(nèi)容 :

-- "-s"選項(xiàng) : 設(shè)置默認(rèn)的過濾器, 如 我們想要輸出 "System.out" 標(biāo)簽的信息, 就可以使用 adb logcat -s System.out 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_2" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -s System.out
  2. --------- beginning of /dev/log/system
  3. --------- beginning of /dev/log/main
  4. I/System.out(22930): GSM -91
  5. I/System.out(22930): SignalStrength issssssssss : -91
  6. I/System.out(22930): GSM -91
  7. I/System.out(22930): SignalStrength issssssssss : -91
  8. I/System.out(22930): Supervisor Thread
  9. I/System.out(22930): Got run mode

輸出日志信息到文件 :

-- "-f"選項(xiàng) : 該選向后面跟著輸入日志的文件, 使用 adb logcat -f log 命令, 會(huì)出現(xiàn)錯(cuò)誤, 這里我們不推薦使用該選項(xiàng);

[plain] view plaincopy

<embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_3" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -f log
  2. couldn't open output file: Read-only file system

-- ">"輸出 : ">" 后面跟著要輸出的日志文件, 可以將 logcat 日志輸出到文件中, 使用 adb logcat > log 命令, 使用 more log 命令查看日志信息;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_4" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_4" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat > log
  2. ^C
  3. octopus@octopus:~$ more log
  4. --------- beginning of /dev/log/system
  5. V/ActivityManager( 500): We have pending thumbnails: null
  6. V/ActivityManager( 500): getTasks: max=1, flags=0, receiver=null
  7. V/ActivityManager( 500): com.android.settings/.Settings: task=TaskRecord{42392278 #448 A com.android.settings U 0}
  8. V/ActivityManager( 500): We have pending thumbnails: null

指定 logcat 的日志輸出格式 :

-- "-v"選項(xiàng) : 使用 adb logcat -v time 命令, 可以啥看日志的輸出時(shí)間;

-- "brief"格式 : 這是默認(rèn)的日志格式 " 優(yōu)先級(jí) / 標(biāo)簽 (進(jìn)程ID) : 日志信息 ", 使用 adb logcat -v prief 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_5" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_5" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=5&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -v brief
  2. --------- beginning of /dev/log/system
  3. D/PowerManagerService( 500): handleSandman: canDream=true, mWakefulness=Awake
  4. D/PowerManagerService( 500): releaseWakeLockInternal: lock=1101267696, flags=0x0

-- "process"格式 : " 優(yōu)先級(jí) (進(jìn)程ID) : 日志信息 ", 使用 adb logcat -v process 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_6" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_6" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=6&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -v process
  2. --------- beginning of /dev/log/system
  3. D( 500) MobileDataStateReceiver received: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED_MOBILE [wap] (MobileDataStateTracker)
  4. V( 500) Broadcast: Intent { act=android.intent.action.ANY_DATA_STATE_MOBILE flg=0x10 (has extras) } ordered=true userid=0 (ActivityManager)
  5. D( 500) wap: Intent from SIM 0, current SIM 0, current DataState DISCONNECTED (MobileDataStateTracker)
  6. D( 500) wap: wap setting isAvailable to false (MobileDataStateTracker)
  7. D( 500) wap: Received state=DISCONNECTED, old=DISCONNECTED, reason=dataDetached (MobileDataStateTracker)
  8. D( 500) BDC-Calling finishReceiver: IIntentReceiver=41c46ba0 (ActivityThread)

-- "tag"格式 : " 優(yōu)先級(jí) / 標(biāo)簽 : 日志信息", 使用 adb logcat -v tag 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_7" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_7" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=7&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -v tag
  2. --------- beginning of /dev/log/system
  3. I/PowerManagerService: setBrightness mButtonLight 0.
  4. D/PowerManagerService: updateScreenStateLocked: mDisplayReady=true, newScreenState=2, mWakefulness=1, mWakeLockSummary=0x1, mUserActivitySummary=0x1, mBootCompleted=true
  5. D/PowerManagerService: handleSandman: canDream=true, mWakefulness=Awake

-- "thread"格式 : " 優(yōu)先級(jí) ( 進(jìn)程ID : 線程ID) 標(biāo)簽 : 日志內(nèi)容 ", 使用 adb logcat -v tag 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_8" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_8" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=8&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -v thread
  2. --------- beginning of /dev/log/system
  3. V( 500: 2141) getTasks: max=1, flags=0, receiver=null
  4. V( 500: 2141) com.lewa.launcher/.Launcher: task=TaskRecord{41dccc20 #425 A com.lewa.launcher U 0}
  5. V( 500: 2141) We have pending thumbnails: null
  6. V( 500: 2140) getTasks: max=1, flags=0, receiver=null

-- "raw"格式 : 只輸出日志信息, 不附加任何其他 信息, 如 優(yōu)先級(jí) 標(biāo)簽等, 使用 adb logcat -v raw 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_9" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_9" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=9&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -v raw
  2. --------- beginning of /dev/log/system
  3. notifications are enabled for com.kindroid.security
  4. Assigned score=0 to Notification(pri=0 contentView=com.kindroid.security/0x7f030052 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[null])
  5. Native set alarm :Alarm{41e1ca00 type 3 com.kindroid.security}
  6. reset poweroff alarm none

-- "time"格式 : "日期 時(shí)間 優(yōu)先級(jí) / 標(biāo)簽 (進(jìn)程ID) : 進(jìn)程名稱 : 日志信息 " , 使用 adb logcat -v time 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_10" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_10" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=10&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -v time
  2. --------- beginning of /dev/log/system
  3. 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
  4. 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])
  5. 04-25 17:18:13.158 V/NotificationService( 500): notifications are enabled for com.kindroid.security
  6. 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])
  7. 04-25 17:18:13.555 V/ActivityManager( 500): getTasks: max=1, flags=0, receiver=null

-- "long"格式 : " [ 日期 時(shí)間 進(jìn)程ID : 線程ID 優(yōu)先級(jí) / 標(biāo)簽] 日志信息 ", 輸出以上提到的所有的頭信息, 使用 adb logcat -v long 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_11" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_11" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=11&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -v long

  2. --------- beginning of /dev/log/system

  3. [ 04-25 17:21:18.118 500:0x2fe V/ActivityManager ]

  4. We have pending thumbnails: null

  5. [ 04-25 17:21:18.696 593:0x251 W/ActivityThread ]

  6. Content provider com.android.providers.telephony.TelephonyProvider already published as telephony

  7. [ 04-25 17:21:19.119 500:0x396 V/ActivityManager ]

  8. getTasks: max=1, flags=0, receiver=null

清空日志緩存信息 : 使用 adb logcat -c 命令, 可以將之前的日志信息清空, 重新開始輸出日志信息;

將緩存日志輸出 : 使用 adb logcat -d 命令, 輸出命令, 之后推出命令, 不會(huì)進(jìn)行阻塞;

輸出最近的日志 : 使用 adb logcat -t 5 命令, 可以輸出最近的5行日志, 并且不會(huì)阻塞;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_12" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_12" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=12&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -t 5
  2. --------- beginning of /dev/log/system
  3. --------- beginning of /dev/log/main
  4. W/ADB_SERVICES(10028): adb: unable to open /proc/10028/oom_adj
  5. D/dalvikvm(23292): threadid=11: created from interp
  6. D/dalvikvm(23292): start new thread
  7. D/dalvikvm(23292): threadid=11: notify debugger
  8. D/dalvikvm(23292): threadid=11 (Thread-24538): calling run()
  9. octopus@octopus:~$

查看日志緩沖區(qū)信息 : 使用 adb logcat -g 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_13" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_13" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=13&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -g
  2. /dev/log/main: ring buffer is 256Kb (255Kb consumed), max entry is 5120b, max payload is 4076b
  3. /dev/log/system: ring buffer is 256Kb (255Kb consumed), max entry is 5120b, max payload is 4076b
  4. octopus@octopus:~$

加載日志緩沖區(qū) : 使用 adb logcat -b 緩沖區(qū)類型 命令;

--** Android中的日志緩沖區(qū)** : system緩沖區(qū) - 與系統(tǒng)相關(guān)的日志信息, radio緩沖區(qū) - 廣播電話相關(guān)的日志信息, events緩沖區(qū) - 事件相關(guān)的日志信息, main緩沖區(qū) - 默認(rèn)的緩沖區(qū);

[plain] view plaincopy

<embed id="ZeroClipboardMovie_14" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_14" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=14&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -b radio -t 5
  2. D/PHONE (23599): [GeminiDataSubUtil] UAPP_C6-4
  3. D/GSM (23599): [GDCT][simId1]apnType = default
  4. D/GSM (23599): [GDCT][simId1]isDataAllowed: not allowed due to - gprs= 1 - SIM not loaded - desiredPowerState= false
  5. D/GSM (23599): [GDCT][simId1]isDataPossible(default): possible=false isDataAllowed=false apnTypePossible=true apnContextisEnabled=true apnContextState()=IDLE
  6. I/MUXD (23591): [gsm0710muxd] 3426:main(): Frames received/dropped: 18242/0
  7. octopus@octopus:~$
  8. octopus@octopus:~$ adb logcat -b main -t 5
  9. D/NotificationService( 500): notification.sound=null
  10. D/NotificationService( 500): mDmLock=false
  11. I/ATCIJ (16576): Couldn't find 'atci-serv-fw' socket; retrying after timeout
  12. W/ADB_SERVICES( 246): create_local_service_socket() name=shell:export ANDROID_LOG_TAGS="" ; exec logcat -b main -t 5
  13. W/ADB_SERVICES(16815): adb: unable to open /proc/16815/oom_adj
  14. octopus@octopus:~$
  15. octopus@octopus:~$ adb logcat -b system -t 5
  16. D/PowerManagerService( 500): updateScreenStateLocked: mDisplayReady=true, newScreenState=0, mWakefulness=0, mWakeLockSummary=0x1, mUserActivitySummary=0x0, mBootCompleted=true
  17. D/PowerManagerService( 500): handleSandman: canDream=false, mWakefulness=Asleep
  18. 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])
  19. V/NotificationService( 500): notifications are enabled for com.kindroid.security
  20. 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])
  21. octopus@octopus:~$
  22. octopus@octopus:~$ adb logcat -b event -t 5
  23. Unable to open log device '/dev/log/event': No such file or directory
  24. octopus@octopus:~$ adb logcat -b events -t 5
  25. I/notification_cancel( 500): [com.kindroid.security,1026,NULL,0,0,64]
  26. 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])]
  27. I/notification_cancel( 500): [com.kindroid.security,1026,NULL,0,0,64]
  28. 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])]
  29. I/notification_cancel( 500): [com.kindroid.security,1026,NULL,0,0,64]
  30. octopus@octopus:~$

以二進(jìn)制形式輸出日志 : 使用 adb logcat -B 命令;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_15" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_15" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=15&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat -B -t 5
  2. O???_?3ZS??4?gps_mt3326nmea_reader_parse: line = 1218GPS get accuracy failed, fix mode:1
  3. ^???_?3ZS??=?gps_mt3326nmea_reader_addc: line = 1331the structure include nmea_cb address is 0x658cc8e8
  4. H???_?3ZSEGE?gps_mt3326nmea_reader_addc: line = 1332nmea_cb address is 0x5d2fe279
  5. i???3ZS?)>?ADB_SERVICEScreate_local_service_socket() name=shell:export ANDROID_LOG_TAGS="" ; exec logcat -B -t 5
  6. 7EE?3ZSo?Y?ADB_SERVICESadb: unable to open /proc/17706/oom_adj

<a name="t2" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a><a target="_blank" name="t2" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>(2) 過濾項(xiàng)解析

過濾項(xiàng)格式 : <tag>[:priority] , 標(biāo)簽:日志等級(jí), 默認(rèn)的日志過濾項(xiàng)是 " *:I " ;

-- V : Verbose (明細(xì));

-- D : Debug (調(diào)試);

-- I : Info (信息);

-- W : Warn (警告);

--** E** : Error (錯(cuò)誤);

--** F **: Fatal (嚴(yán)重錯(cuò)誤);

-- S : Silent(Super all output) (最高的優(yōu)先級(jí), 可能不會(huì)記載東西);

過濾指定等級(jí)日志 : 使用** adb logcat 10 :E* 命令, 顯示 Error 以上級(jí)別的日志;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_16" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_16" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=16&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat *:E

  2. Note: log switch off, only log_main and log_events will have logs!

  3. --------- beginning of /dev/log/main

  4. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  5. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  6. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  7. E/dalvikvm( 756): GC_CONCURRENT freed 1809K, 27% free 19489K/26695K, paused 16ms+5ms, total 109ms

  8. E/WifiHW ( 441): wifi_send_command : SCAN ; interface index=0;

  9. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  10. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  11. E/dalvikvm( 756): GC_CONCURRENT freed 1820K, 27% free 19490K/26695K, paused 16ms+3ms, total 102ms

  12. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  13. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

過濾指定標(biāo)簽等級(jí)日志 : 使用 *adb logcat WifiHW:D :S 命令進(jìn)行過濾;

-- 命令含義 : 輸出10條日志, 日志是 標(biāo)簽為 WifiHW, 并且優(yōu)先級(jí) Debug(調(diào)試) 等級(jí)以上的級(jí)別的日志;

-- *注意 :S : 如果沒有 *S 就會(huì)輸出錯(cuò)誤;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_17" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_17" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=17&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat WifiHW:D *:S

  2. Note: log switch off, only log_main and log_events will have logs!

  3. --------- beginning of /dev/log/main

  4. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  5. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  6. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  7. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  8. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  9. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  10. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

可以同時(shí)設(shè)置多個(gè)過濾器 : 使用 *adb logcat WifiHW:D dalvikvm:I :S 命令, 輸出 WifiHW 標(biāo)簽 的 Debug 以上級(jí)別 和 dalvikvm 標(biāo)簽的 Info 以上級(jí)別的日志;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_18" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=18&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat WifiHW:D dalvikvm:I *:S

  2. Note: log switch off, only log_main and log_events will have logs!

  3. --------- beginning of /dev/log/main

  4. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  5. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  6. E/dalvikvm( 756): GC_CONCURRENT freed 1820K, 27% free 19490K/26695K, paused 17ms+2ms, total 110ms

  7. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  8. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  9. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  10. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

  11. E/dalvikvm( 756): GC_CONCURRENT freed 1810K, 27% free 19489K/26695K, paused 17ms+5ms, total 108ms

  12. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;

  13. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;

<a name="t3" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a><a target="_blank" name="t3" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>2. 使用管道過濾日志

<a name="t4" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a><a target="_blank" name="t4" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>(1) 過濾固定字符串

過濾固定字符串 : 只要命令行出現(xiàn)的日志都可以過濾, 不管是不是標(biāo)簽;

-- 命令 : adb logcat | grep Wifi ;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_19" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_19" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=19&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. octopus@octopus:~$ adb logcat | grep Wifi
  2. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
  3. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
  4. E/WifiHW ( 441): wifi_send_command : SCAN ; interface index=0;
  5. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
  6. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
  7. E/WifiHW ( 441): wifi_send_command : AP_SCAN 1 ; interface index=0;
  8. E/WifiHW ( 441): wifi_send_command : SCAN_RESULTS ; interface index=0;
image

過濾字符串忽略大小寫 : adb logcat | grep -i wifi ;

image

<a name="t5" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a><a target="_blank" name="t5" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>(2) 使用正則表達(dá)式匹配

分析日志 : 該日志開頭兩個(gè)字符是 "V/", 后面開始就是標(biāo)簽, 寫一個(gè)正則表達(dá)式 "^..ActivityManager", 就可以匹配日志中的 "V/ActivityManager" 字符串;

[plain] view plaincopy

<embed id="ZeroClipboardMovie_20" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_20" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=20&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

  1. V/ActivityManager( 574): getTasks: max=1, flags=0, receiver=null

**正則表達(dá)式過濾日志 **: 使用上面的正則表達(dá)式組成命令 adb logcat | grep "^..Activity" ;

image
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌荣回,老刑警劉巖柔纵,帶你破解...
    沈念sama閱讀 210,978評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件孝冒,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡屁倔,警方通過查閱死者的電腦和手機(jī)票罐,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,954評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門叉趣,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人该押,你說我怎么就攤上這事疗杉。” “怎么了蚕礼?”我有些...
    開封第一講書人閱讀 156,623評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵烟具,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我闻牡,道長(zhǎng)净赴,這世上最難降的妖魔是什么绳矩? 我笑而不...
    開封第一講書人閱讀 56,324評(píng)論 1 282
  • 正文 為了忘掉前任罩润,我火速辦了婚禮,結(jié)果婚禮上翼馆,老公的妹妹穿的比我還像新娘割以。我一直安慰自己,他們只是感情好应媚,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,390評(píng)論 5 384
  • 文/花漫 我一把揭開白布严沥。 她就那樣靜靜地躺著,像睡著了一般中姜。 火紅的嫁衣襯著肌膚如雪消玄。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,741評(píng)論 1 289
  • 那天丢胚,我揣著相機(jī)與錄音翩瓜,去河邊找鬼。 笑死携龟,一個(gè)胖子當(dāng)著我的面吹牛兔跌,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播峡蟋,決...
    沈念sama閱讀 38,892評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼坟桅,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼华望!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起仅乓,我...
    開封第一講書人閱讀 37,655評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤赖舟,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后方灾,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體建蹄,經(jīng)...
    沈念sama閱讀 44,104評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,451評(píng)論 2 325
  • 正文 我和宋清朗相戀三年裕偿,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了洞慎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,569評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡嘿棘,死狀恐怖劲腿,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情鸟妙,我是刑警寧澤焦人,帶...
    沈念sama閱讀 34,254評(píng)論 4 328
  • 正文 年R本政府宣布,位于F島的核電站重父,受9級(jí)特大地震影響花椭,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜房午,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,834評(píng)論 3 312
  • 文/蒙蒙 一矿辽、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧郭厌,春花似錦袋倔、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,725評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至扇售,卻和暖如春前塔,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背承冰。 一陣腳步聲響...
    開封第一講書人閱讀 31,950評(píng)論 1 264
  • 我被黑心中介騙來泰國(guó)打工华弓, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人巷懈。 一個(gè)月前我還...
    沈念sama閱讀 46,260評(píng)論 2 360
  • 正文 我出身青樓该抒,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子凑保,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,446評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • adb的全稱為Android Debug Bridge.是android司機(jī)經(jīng)常用到的工具.但是問題是那么多命令寫...
    香脆的大雞排閱讀 40,609評(píng)論 19 152
  • 1,局部變量如創(chuàng)建的block存放在棧區(qū)冈爹, 2,alloc創(chuàng)建的對(duì)象存放在堆區(qū) 3.全局和靜態(tài)變量存放在全局區(qū)
    赤焰軍少帥林殊閱讀 185評(píng)論 0 0
  • “Echo,你再等我六年芝此,我讀大學(xué)四年憋肖,服兵役兩年,等六年過去了婚苹,我就娶你岸更,好嗎?” “好啊,既然這樣膊升,我們就疏遠(yuǎn)...
    影子影閱讀 11,885評(píng)論 251 477
  • 無論春天還是冬天怎炊,我不喜歡呆在宿舍,我喜歡上自習(xí)廓译,更喜歡出去走走看看评肆,看看外面的大千世界。 上自習(xí)不是目的非区,讓自己...
    照亮Br閱讀 465評(píng)論 2 1
  • 憂郁奔向冷的天閱讀 156評(píng)論 0 1