原文地址::http://blog.chinaunix.net/uid-25581264-id-3379198.html
相关文章
1、Logcat过滤日志输出到文件----https://blog.youkuaiyun.com/jsjwangmingmin/article/details/88428794
2、adb logcat 通过包名过滤日志并输出到txt文件----https://www.cnblogs.com/slowlysnail/p/8394937.html
3、adb logcat如何过滤多个条件----https://ask.youkuaiyun.com/questions/366288
4、adb logcat命令查看并过滤android输出log----https://wenku.baidu.com/view/a7da85c3a8956bec0975e3a0.html
logcat是Android中一个命令行工具,可以用于得到程序的log信息。
logcat使用方法如下所示:
logcat [options] [filterspecs]
logcat的选项包括:
-s 设置过滤器,例如指定 '*:s'
-f 输出到文件,默认情况是标准输出。
-r [] Rotate log every kbytes. (16 if unspecified). Requires -f
-n Sets max number of rotated logs to , default 4
-v 设置log的打印格式, 是下面的一种:
brief process tag thread raw time threadtime long
-c 清除所有log并退出
-d 得到所有log并退出 (不阻塞)
-g 得到环形缓冲区的大小并退出
-b 请求不同的环形缓冲区 ('main' (默认), 'radio', 'events')
-B 输出log到二进制中。
过滤器的格式是一个这样的串:
[:priority]
其中 表示log的component, tag (或者使用 * 表示所有) , priority 如下所示:
V Verbose
D Debug
I Info
W Warn
E Error
F Fatal
S Silent
****************************************************************************
过滤器使用小课堂:
I/ActivityManager( 52): Displayed activity com.android.contacts/.DialtactsContactsEntryActivity: 983 ms
上述log中,tag=ActivityMangager;priority=I
tag的定义在源码中定义,例如:
AudioRecord.app中
#define LOG_TAG "AudioRecord"
此文件中的LOGX打印的TAG就是AudioRecord
log级别是大于等于设定级别,LOGV对应V(Verbose)级别,LOGD对应D(Debug)级别
如果你要只输出此文件中的错误信息
则:#logcat -s AudioRecord:E
就会输出大于等于Error的log信息
同理,同时设置多个log过滤器
#logcat -s AudioRecord:E AudioTrack:V AudioFlinger:W
有问题可以留言!
//===========================================================================================
本人备注
Unrecognized Option i
Usage: logcat [options] [filterspecs]
options include:
-s Set default filter to silent. Equivalent to filterspec '*:S'
-f <file>, --file=<file> Log to file. Default is stdout
-r <kbytes>, --rotate-kbytes=<kbytes>
Rotate log every kbytes. Requires -f option
-n <count>, --rotate-count=<count>
Sets max number of rotated logs to <count>, default 4
-v <format>, --format=<format>
Sets the log print format, where <format> is:
brief color epoch long monotonic printable process raw
tag thread threadtime time uid usec UTC year zone
-D, --dividers Print dividers between each log buffer
-c, --clear Clear (flush) the entire log and exit
if Log to File specified, clear fileset instead
-d Dump the log and then exit (don't block)
-e <expr>, --regex=<expr>
Only print lines where the log message matches <expr>
where <expr> is a regular expression
-m <count>, --max-count=<count>
Quit after printing <count> lines. This is meant to be
paired with --regex, but will work on its own.
--print Paired with --regex and --max-count to let content bypass
regex filter but still stop at number of matches.
-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...'
'YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format
-g, --buffer-size Get the size of the ring buffer.
-G <size>, --buffer-size=<size>
Set size of log ring buffer, may suffix with K or M.
-L, -last Dump logs from prior to last reboot
-b <buffer>, --buffer=<buffer> Request alternate ring buffer, 'main',
'system', 'radio', 'events', 'crash', 'default' or 'all'.
Multiple -b parameters or comma separated list of buffers are
allowed. Buffers interleaved. Default -b main,system,crash.
-B, --binary Output the log in binary.
-S, --statistics Output statistics.
-p, --prune 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> ...', --prune='<list> ...'
Set prune white and ~black list, using same format as
listed above. Must be quoted.
--pid=<pid> Only prints logs from the given pid.
--wrap Sleep for 2 hours or when buffer about to wrap whichever
comes first. Improves efficiency of polling by providing
an about-to-wrap wakeup.
filterspecs are a series of
<tag>[:priority]
where <tag> is a log component tag (or * for all) and priority is:
V Verbose (default for <tag>)
D Debug (default for '*')
I Info
W Warn
E Error
F Fatal
S Silent (suppress all output)
'*' by itself means '*:D' and <tag> by itself means <tag>:V.
If no '*' filterspec or -s on command line, all filter defaults to '*:V'.
eg: '*:S <tag>' prints only <tag>, '<tag>:S' suppresses all <tag> log messages.
If not specified on the command line, filterspec is set from ANDROID_LOG_TAGS.
If not specified with -v on command line, format is set from ANDROID_PRINTF_LOG
or defaults to "threadtime"