转载自:http://www.cnblogs.com/flyingcode/p/5280501.html

Android日志系统提供了记录和查看系统调试信息的功能。日志都是从各种软件和一些系统的缓冲区中记录下来的,缓冲区可以通过logcat命令来查看和使用.

在使用logcat之前,请确保手机的USB调试模式已经开启,可以通过"Setting->Application->Development->USB debugging"来开启。
logcat本身是android的shell的一个命令,你可以通过“adb shell”进入shell后执行logcat命令,也可以通过"adb logcat"直接运行。
语法:
[adb] logcat [<option>] ... [<filter-spec>] ...
选项:
-b <buffer> 指定要查看的日志缓冲区,可以是system,events ,radio,main . 默认值是system和main 。
-c 清楚屏幕上的日志. 
-d 输出日志到屏幕上. 
-f <filename> 指定输出日志信息的<filename> ,默认是stdout . 
-g 输出指定的日志缓冲区,输出后退出. 
-n <count> 设置日志的最大数目<count> .,默认值是4,需要和 -r 选项一起使用。 
-r <kbytes> 每<kbytes> 时输出日志,默认值为16,需要和-f 选项一起使用. 
-s 设置默认的过滤级别为silent. 
-v <format> 设置日志输入格式,默认的是brief 格式,要知道更多的支持的格式,参看Controlling Log Output 
参数<filter-spec>

参数<filter-spec>用于对某类的tag的日志输出进行过滤。每一个输出的Android日志信息都有一个tag和它的优先级.

日志的标签是系统部件原始信息的一个简要的标志。这个tag就是Log.i,Log.d,Log.i,Log.w,Log.e,Log.wtf系列函数中的tag.
对于System.out.print系列函数所对于的tag,其实就是"System.out"
<filter-spec>以“tag:priority”的形式来对日志输出进行过滤的
优先级priority有以下几种,按照从低到高顺利排列如下:
V — Verbose (lowest priority) 对应于Log.i()系列函数
D — Debug 对应于Log.d()系列函数
I — Info 对应于Log.i()系列函数
W — Warning 对应于Log.w()系列函数
E — Error 对应于Log.e()系列函数
F — Fatal 对应于Log.wtf()系列函数
S — Silent (highest priority, on which nothing s ever printed)
在运行logcat的时候在前两列的信息中你就可以看到 logcat 的标签列表和优先级别,它是这样标出的:<priority>/<tag> .
<filter-spec>中的优先级是指显示该优先级即其以上优先级得日志。比如对于robin:D表示显示tag为robin的所有Debug及其以上优先级的日志。<filter-spec>只是的针对某类的tag的日志进行过滤,如果有多个针对同一个tag的过滤的话,以最后一个为准。另外对于tag,可以使用通配符。对于在tag中没有使用统配符的<filter-spec>,我称它为显式的日志过滤器;而对于在tag中使用统配符的,我称它它为隐式的日志过滤器。如果这两种过滤器有对着同一个tag的过滤的话,以显示的日志过滤器为准。如果是同一种的话(显式/隐式),以后一个为准。
因为<filter-spec>只是指明了对某一类tag应该进行如何过滤,它没说明的其他tag,将采用系统默认的方式(*:V),即全部输出。我们可以通过选项"-s"来设置<filter-spec>中没有说明的tag来都不输出,相当于"*.S"
实例1:
adb logcat -s robin:i
这样将显现tag为robin的Info及以上优先级的所有的日志。该命令等同于adb logcat robin:i *:S
-b 选项
该选项用于指定要操作的日志缓冲区,可以是system,events ,radio,main .它们分别对应/dev/log文件夹下的system,events ,radio,main日志文件 。系统默认的是system和main 。该选项可以出现多次,以指定多个日志缓冲去。
比如:
adb logcat -b system -b main -b events -b radio -s robin:i
日志输出的开头几行说明了你当前查看的哪些日志缓冲区,比如上面的语句的前几行就是:
--------- beginning of /dev/log/radio
--------- beginning of /dev/log/events
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main

其实“adb logcat -s robin:i”相当于“adb logcat -b system -b main -s robin:i”。我们的Log.i,Log.d,Log.i,Log.w,Log.e,Log.wtf系列函数及System.out.print系列函数以及System.erro.print系列都输出到了main缓冲区。因此我们一般用默认的就足够了。
events缓冲区对应的日志文件/system/etc/event-log-tags,使用android.util.EventLog生成的日志就输出到该缓冲区。
android.database.sqlite.SQLiteDatabase的logTimeStat()函数就是使用EventLog来进行日志输出的
-c 选项
该选项用于清空你所指定的日志缓冲区。应该就是清除其对应的日志文件
-s 选项
该选项将把tag的默认过滤级别设置为silent,这样tag默认就不显示。系统把tag的默认过滤级别是设置为Verbose,这样其tag默认就是要显示的。
-f 选项

该选项指定输出日志信息的<filename> ,默认是stdout . 但是这里的文件是指android系统上的文件。如果我们想把日志输出到本地window系统的话,请采用如下形式的命令:

adb logcat -s robin:i>1.log
这样日志就输出了你的window的当前目录的1.log文件中。
-v 选项
日志信息包括了许多元数据域包括标签和优先级。可以通过-v选项可以用来指定日志的输出格式,以显示出特定的元数据域。
brief — Display priority/tag and PID of originating process (the default format).显示prority/tag,产生日志的进程的id,和日志消息本身。它是日志默认的输出格式。
process — Display PID only.显示priority,产生日志的进程的id,和日志消息本身
tag — Display the priority/tag only.显示prority/tag,和消息本身
thread — Display process:thread and priority/tag only.显示priority,线程和日志消息本身
raw — Display the raw log message, with no other metadata fields.只显示消息本身
time — Display the date, invocation time, priority/tag, and PID of the originating process.显示产生日志的时间,prority/tag,产生日志的进程Id,和日志消息本身。
long — Display all metadata fields and separate messages with a blank lines.显示产生日志的时间,prority/tag,产生日志的进程Id,和日志消息本身。但是日志消息本身另其一行进行显示。每个日志之间空一行。
当启动了logcat ,你可以通过-v 选项来指定输出格式:
[adb] logcat [-v <format>]
实例2:
adb logcat -v time -s robin:v
注意是通过-v 选项来设置输出格式.

1. 解析 adb logcat 的帮助信息

在命令行中输入 adb logcat --help 命令, 就可以显示该命令的帮助信息;

[plain] view plaincopy
  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 [选项] [过滤项], 其中 选项 和 过滤项 在 中括号 [] 中, 说明这是可选的;

(1) 选项解析

选项解析 :

-- "-s"选项 : 设置输出日志的标签, 只显示该标签的日志;

--"-f"选项 : 将日志输出到文件, 默认输出到标准输出流中, -f 参数执行不成功;

--"-r"选项 : 按照每千字节输出日志, 需要 -f 参数, 不过这个命令没有执行成功;

--"-n"选项 : 设置日志输出的最大数目, 需要 -r 参数, 这个执行 感觉 跟 adb logcat 效果一样;

--"-v"选项 : 设置日志的输出格式, 注意只能设置一项;

--"-c"选项 : 清空所有的日志缓存信息;

--"-d"选项 : 将缓存的日志输出到屏幕上, 并且不会阻塞;

--"-t"选项 : 输出最近的几行日志, 输出完退出, 不阻塞;

--"-g"选项 : 查看日志缓冲区信息;

--"-b"选项 : 加载一个日志缓冲区, 默认是 main, 下面详解;

--"-B"选项 : 以二进制形式输出日志;

.

输出指定标签内容 :

-- "-s"选项 : 设置默认的过滤器, 如 我们想要输出 "System.out" 标签的信息, 就可以使用adb logcat -s System.out 命令;

[plain] view plaincopy
  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"选项 : 该选向后面跟着输入日志的文件, 使用adb logcat -f /sdcard/log.txt 命令, 注意这个log文件是输出到手机上,需要指定合适的路径。

[plain] view plaincopy
  1. octopus@octopus:~$ adb logcat -f /sdcard/log.txt

这个参数对对不能一直用电脑连着手机收集日志的场景非常有用,其实android shell下也有一个相同参数的logcat命令。使用如下命令可以执行后断开PC和手机持续收集LOG。

[plain] view plain copy  
  1. shell@pc$ adb shell
  2. shell@android$ logcat -f /sdcard/log.txt &   #这里的&符号表示后台执行,别少了。
  3. shell@android$ exit

注:

(1)以上shell@pc$ 指在pc的shell终端执行后边的命令, shell@android$ 表示在手机shell中执行后边的命令l

(2)一定注意合适的时候需要停止掉以上命令,否则再次使用相同命令的时候,就会有两个logcat写同一个文件了

停止方法:  adb shell kill -9 <logcat_pid>

其中logcat_pid 通过 如下命令获取

adb shell ps | grep logcat          # linux 平台

adb shell ps | findstr "logcat"    #Windows平台

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

[plain] view plaincopy
  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

-- " -d -f <log>" 组合命令:可以将日志保存到手机上的指定位置,对不能一直用电脑连着手机收集日志的场景非常有用。

[plain] view plain copy  
  1. adb logcat -d -v /sdcard/mylog.txt

指定 logcat 的日志输出格式 :

-- "-v"选项 : 使用adb logcat -v time 命令, 可以啥看日志的输出时间;

使用adb logcat -v threadtime 命令, 可以啥看日志的输出时间和线程信息;

-- "brief"格式 : 这是默认的日志格式" 优先级 / 标签 (进程ID) : 日志信息 ", 使用adb logcat -v prief 命令;

[plain] view plaincopy
  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"格式 : " 优先级 (进程ID) : 日志信息 ", 使用adb logcat -v process 命令;

[plain] view plaincopy
  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"格式 : " 优先级 / 标签 : 日志信息", 使用adb logcat -v tag 命令;

[plain] view plaincopy
  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"格式 : " 优先级 ( 进程ID : 线程ID) 标签 : 日志内容 ", 使用adb logcat -v tag 命令;

[plain] view plaincopy
  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"格式 : 只输出日志信息, 不附加任何其他 信息, 如 优先级 标签等, 使用adb logcat -v raw 命令;

[plain] view plaincopy
  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"格式 "日期 时间 优先级 / 标签 (进程ID) : 进程名称 : 日志信息 ", 使用adb logcat -v time 命令;

[plain] view plaincopy
  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"格式:" [ 日期 时间 进程ID : 线程ID 优先级 / 标签] 日志信息 ", 输出以上提到的所有的头信息, 使用adb logcat -v long 命令;

[plain] view plaincopy
  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 命令, 输出命令, 之后推出命令, 不会进行阻塞;

输出最近的日志 : 使用adb logcat -t 5 命令, 可以输出最近的5行日志, 并且不会阻塞;

[plain] view plaincopy
  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:~$

查看日志缓冲区信息 : 使用 adb logcat -g 命令;

[plain] view plaincopy
  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:~$

加载日志缓冲区 : 使用 adb logcat -b 缓冲区类型 命令;

-- Android中的日志缓冲区 : system缓冲区 - 与系统相关的日志信息, radio缓冲区 - 广播电话相关的日志信息, events缓冲区 - 事件相关的日志信息, main缓冲区 - 默认的缓冲区;

[plain] view plaincopy
  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:~$

以二进制形式输出日志 : 使用 adb logcat -B 命令;

[plain] view plaincopy
  1. octopus@octopus:~$ adb logcat -B  -t 5
  2. O��_�3ZS�4gps_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��_�3ZSEGEgps_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. 7*E*E�3ZSo�YADB_SERVICESadb: unable to open /proc/17706/oom_adj

(2) 过滤项解析

过滤项格式 : <tag>[:priority] , 标签:日志等级, 默认的日志过滤项是 " *:I " ;

-- V : Verbose (明细);

-- D : Debug (调试);

-- I : Info (信息);

-- W : Warn (警告);

-- E : Error (错误);

-- F: Fatal (严重错误);

-- S : Silent(Super all output) (最高的优先级, 可能不会记载东西);

过滤指定等级日志 : 使用 adb logcat 10 *:E 命令, 显示 Error 以上级别的日志;

[plain] view plaincopy
  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;

过滤指定标签等级日志 : 使用 adb logcat WifiHW:D *:S 命令进行过滤;

-- 命令含义 : 输出10条日志, 日志是 标签为 WifiHW, 并且优先级 Debug(调试) 等级以上的级别的日志;

--注意 *:S : 如果没有 *S 就会输出错误;

[plain] view plaincopy
  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;

可以同时设置多个过滤器 : 使用adb logcat WifiHW:D dalvikvm:I *:S 命令, 输出 WifiHW 标签 的 Debug 以上级别 和 dalvikvm 标签的 Info 以上级别的日志;

[plain] view plaincopy
  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;

2. 使用管道过滤日志

(1) 过滤固定字符串

过滤固定字符串 : 只要命令行出现的日志都可以过滤, 不管是不是标签;

-- 命令 : adb logcat | grep Wifi ;

[plain] view plaincopy
  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;

过滤字符串忽略大小写 : adb logcat | grep -i wifi ;

(2) 使用正则表达式匹配

分析日志 : 该日志开头两个字符是 "V/", 后面开始就是标签, 写一个正则表达式 "^..ActivityManager", 就可以匹配日志中的 "V/ActivityManager" 字符串;

[plain] view plaincopy
  1. V/ActivityManager(  574): getTasks: max=1, flags=0, receiver=null

正则表达式过滤日志: 使用上面的正则表达式组成命令 adb logcat | grep "^..Activity" ;

android logcat 命令详解相关推荐

  1. Android logcat命令详解

    一.logcat命令介绍 1.android log系统 2.logcat介绍 logcat是android中的一个命令行工具,可以用于得到程序的log信息 log类是一个日志类,可以在代码中使用lo ...

  2. Android的Logcat命令详解:翻译Enabling logcat Logging

    Android的Logcat命令详解 --翻译Enabling logcat Logging 田海立@CSDN 2011/07/28 Android LOG系统提供了收集和查看系统调试输出的功能.各种 ...

  3. android route命令详解,route cmd命令详解

    在本地 IP 路由表中显示和修改条目.使用不带参数的 route 可以显示帮助.接下来是小编为大家收集的route cmd命令详解,希望能帮到大家. route cmd命令详解 语法 route [- ...

  4. android+tracert命令详解,tracert 命令详解(示例代码)

    tracert 命令详解 How to Use the TRACERT Utility The TRACERT diagnostic utility determines the route to a ...

  5. Android LogCat使用详解

    Android的Logcat用于显示系统的调试信息,可在分别以下几个地方查看和调用logcat:  1.eclipse的Debug模式或DDMS模式下的会有一个Logcat窗口,用于显示log日志  ...

  6. logcat命令详解

    一.logcat命令介绍 1.android log系统 2.logcat介绍 logcat是android中的一个命令行工具,可以用于得到程序的log信息 log类是一个日志类,可以在代码中使用lo ...

  7. android sqlite 参数,Android SQLite3命令详解教程

    SQLite3可以让我们手动的对SQLite数据库进行管理.一共有2个sqlite3,一个在电脑上,它位于 android-sdk-windows\tools\sqlite3.exe,用于电脑上SQL ...

  8. Android pm 命令详解

    一.pm命令介绍与包名信息查询 1.pm命令介绍 pm工具为包管理(package manager)的简称 可以使用pm工具来执行应用的安装和查询应用宝的信息.系统权限.控制应用 pm工具是Andro ...

  9. Android pm命令详解

    在看相关PackageManager代码时,无意中发现Android 下提供一个pm命令,通常放在/system/bin/下.这个命令与Package有关,且非常实用.所以研究之. 0. Usage: ...

最新文章

  1. java之ibatis数据缓存
  2. SAP库存管理预留功能评测
  3. UEFI+GPT安装Windows8和CentOS双系统
  4. 求任意大小矩阵的转置矩阵
  5. android jni调用so库
  6. 【LCT】遥远的国度(P3979)
  7. 数据结构图文解析之:哈夫曼树与哈夫曼编码详解及C++模板实现
  8. mac 下安装java, jmeter, ant, jenkins,使用jmeter+ant+jenkins 接口测试集成工具,发送html报告到邮箱中
  9. Jmeter中Websocket协议支持包的使用 (转)
  10. Windows Phone 模拟器安装使用详解
  11. Highlighting高亮插件使用说明
  12. 高通抓取ramdump
  13. 后端返回base64格式数据转excel格式文件并下载
  14. mysql 主键和候选键_2.2.2 候选键与主键
  15. 考研数学:常见的初等函数求导公式以及其对应的积分公式
  16. 个人计算机多核cpu好处,多核CPU的优缺点
  17. day29 | 216.组合总和III 17.电话号码的字母组合
  18. 沐风:微信小程序火了,小心掉入陷井!
  19. 计算机怎样检查视力,电脑视力表同样测视力 测试方法要正确
  20. 根据sitemap一键推送给百度收录的python小脚本

热门文章

  1. 计算机学科三大科学形态,计算机科学与技术方法论-计算学科中的三个学科形态ppt...
  2. 三十多岁就别转行做算法了
  3. zabbix监控邮箱报警
  4. 华为的深度学习框架介绍一下
  5. html2canvas 把h5网页保存为图片 区域保存
  6. 万字长文:云架构设计原则
  7. 车载充电机OBC功率级HiL
  8. 数学建模学习笔记(二):非线性规划模型例题与灵敏度分析
  9. java和.net能共存吗_是否能让JAVA 和 .NET框架共存(转)
  10. “筑牢洗钱风险社会防线 助力金融高质量发展” 中荷人寿山东省分公司开展反洗钱宣传活动