使用 logcat 命令
查看和跟踪系统日志缓冲区的命令logcat的一般用法是:
[adb] logcat [<option>] ... [<filter-spec>] ...
调用方式在终端窗口中输入:
adb logcat
//如果指定设备
adb -s [设备ID] logcat
1. 解析 adb logcat 的 帮助信息
//输入命令
adb logcat -help
//输出结果
logcat: invalid option -- h
Unrecognized Option
Usage: logcat [options] [filterspecs]
options include:
-s Set default filter to silent.
Like specifying filterspec '*:s'
-f <filename> Log to file. Default to stdout
-r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f
-n <count> Sets max number of rotated logs to <count>, default 4
-v <format> Sets the log print format, where <format> is one of:
brief process tag thread raw time threadtime long
-c clear (flush) the entire log and exit
-d dump the log and then exit (don't block)
-t <count> print only the most recent <count> lines (implies -d)
-t '<time>' print most recent lines since specified time (implies -d)
-T <count> print only the most recent <count> lines (does not imply -d)
-T '<time>' print most recent lines since specified time (not imply -d)
count is pure numerical, time is 'MM-DD hh:mm:ss.mmm'
-g get the size of the log's ring buffer and exit
-b <buffer> Request alternate ring buffer, 'main', 'system', 'radio',
'events', 'crash' or 'all'. Multiple -b parameters are
allowed and results are interleaved. The default is
-b main -b system -b crash.
-B output the log in binary.
-S output statistics.
-G <size> set size of log ring buffer, may suffix with K or M.
-p print prune white and ~black list. Service is specified as
UID, UID/PID or /PID. Weighed for quicker pruning if prefix
with ~, otherwise weighed for longevity if unadorned. All
other pruning activity is oldest first. Special case ~!
represents an automatic quicker pruning for the noisiest
UID as determined by the current statistics.
-P '<list> ...' set prune white and ~black list, using same format as
printed above. Must be quoted.
filterspecs are a series of
<tag>[:priority]
where <tag> is a log component tag (or * for all) and priority is:
V Verbose
D Debug
I Info
W Warn
E Error
F Fatal
S Silent (supress all output)
'*' means '*:d' and <tag> by itself means <tag>:v
If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.
If no filterspec is found, filter defaults to '*:I'
If not specified with -v, format is set from ANDROID_PRINTF_LOG
or defaults to "brief"
选项解析 :
- "-s"选项 : 设置输出日志的标签, 只显示该标签的日志;
- "-f"选项 : 将日志输出到文件, 默认输出到标准输出流中, -f 参数执行不成功;
- "-r"选项 : 按照每千字节输出日志, 需要 -f 参数, 不过这个命令没有执行成功;
- "-n"选项 : 设置日志输出的最大数目, 需要 -r 参数, 这个执行 感觉 跟 adb logcat 效果一样;
- "-v"选项 : 设置日志的输出格式, 注意只能设置一项;
- "-c"选项 : 清空所有的日志缓存信息;
- "-d"选项 : 将缓存的日志输出到屏幕上, 并且不会阻塞;
- "-t"选项 : 输出最近的几行日志, 输出完退出, 不阻塞;
- "-g"选项 : 查看日志缓冲区信息;
- "-b"选项 : 加载一个日志缓冲区, 默认是 main, 下面详解;
- "-B"选项 : 以二进制形式输出日志;
** Log 优先级是下面的字符,顺序是从低到高 **:
- V — 明细 (最低优先级)
- D — 调试
- I — 信息
- W — 警告
- E — 错误
- F — 严重错误
- S — 无记载 (最高优先级,没有什么会被记载)
输出指定标签内容
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
输出日志信息到文件
octopus@octopus:~$ adb logcat -f /sdcard/log.txt
****过滤指定等级日志****
// 输出 显示 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;
过滤指定标签等级日志 :
// **命令含义** : 输出10条日志, 日志是 标签为 WifiHW, 并且优先级 Debug(调试) 等级以上的级别的日志;
//**注意 *:S** : 如果没有 *S 就会输出错误,*S 代表白名单;
octopus@octopus:~$ adb logcat 10 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 以上级别的日志;
网友评论