logcat命令主要用来获取Android运行时的日志,通过不同的参数可以获取可以获取整个系统不同层面的日志信息。
下面将先对各个参数进行简单介绍,之后会列举一下Android开发过程中常用场景日志抓取命令。
–help
主要用来获取logcat命令帮助信息。
命令:adb logcat -help
[D:~]$ 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: 设置输出日志的标签, 只显示该标签的日志;
清空日志缓存
adb logcat -c
执行该命令后,将清除系统中的所有日志缓存。
radio日志获取
adb logcat -v time -b radio
执行该命令后,就是打印出带时间格式的radio日志。