logcat是android中的一个命令行工具,可以用于得到程序的log信息,使用adb查看log时,中文容易出现乱码,提前先执行CHCP 65001设置一下UTF-8编码。
以下是adb logcat的帮助信息
输入adb logcat –help
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"
1、 -s 设置logcat过滤器
如tag是System.out
使用就是adb logcat -s System.out,这里的tag区分大小写,并且需要完整的tag;
2、-f 输出日志到文件,需要指定手机里合适的路径。
3、-r 设置kbytes大小,和-f结合使用。
4、-n 设置日志的最大数目,和-r结合使用
5、-v 设置日志的输出格式,包括(brief process tag thread raw time threadtime long)
brief 默认,优先级 / 标签 (进程ID) : 日志信息
process , 优先级 (进程ID) : 日志信息
tag,优先级 / 标签 : 日志信息
thread,优先级 ( 进程ID : 线程ID) 标签 : 日志内容
raw,日志内容
time,日期 时间 优先级 / 标签 (进程ID) : 进程名称 : 日志信息
threadtime,
long, 日期 时间 进程ID : 线程ID 优先级 / 标签] 日志信息
如adb logcat -v time 输出带时间的logcat;
adb logcat -v threadtime 带时间和线程信息的logcat
这篇博客介绍了adb logcat的相关命令,包括如何设置过滤器、输出日志到文件、设定日志大小限制、最大数目以及输出格式。重点讲解了不同输出格式如brief、process、tag、thread、raw、time、threadtime和long的用法,帮助读者理解和掌握adb logcat的高级使用技巧。
611

被折叠的 条评论
为什么被折叠?



