首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

logcat 下令小结

2013-09-07 
logcat 命令小结logcat是android系统中的一个命令,是一个可执行的bin文件,放置在/system/bin目录下。root@a

logcat 命令小结

logcat是android系统中的一个命令,是一个可执行的bin文件,放置在/system/bin目录下。

root@android:/system/bin # ls -l logcat                                        -rwxr-xr-x root     shell       13680 2008-08-01 12:00 logcat


logcat的源代码在/system/core下面,根据Android.mk:

# Copyright 2006 The Android Open Source ProjectLOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_SRC_FILES:= logcat.cpp event.logtagsLOCAL_SHARED_LIBRARIES := liblogLOCAL_MODULE:= logcatinclude $(BUILD_EXECUTABLE 

可以看出编译出来是可执行文件。

要是感兴趣可以研究一下。

 

看一下logcat的注释:

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)  -g              get the size of the log's ring buffer and exit  -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio'                  or 'events'. Multiple -b parameters are allowed and the                  results are interleaved. The default is -b main -b system.  -B              output the log in binaryfilterspecs 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>:vIf 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_LOGor defaults to "brief"


解释一下options:

-s 相当于一个过滤器

-f <filename> 输出到文件,默认情况是标准输出.

-r [<kbytes>] 循环log的字节数(默认为16),需要-f.

-n <count> 设置循环log的最大数目,默认是4

-v <format> 设置log的打印格式, <format> 是下面的一种: brief process tag thread raw time threadtime long.

-c 清除所有log并退出.

-d 得到所有log并退出 (不阻塞).

-g 得到环形缓冲区的大小并退出.

-b <buffer> 请求不同的环形缓冲区('main' (默认), 'radio', 'events').

-B 输出log到二进制中.

 

解释一下优先级:

filterspecs are a series of  <tag>[:priority]

where <tag> is a log component tag (or * for all) and priority is: //这个tag可以是用户定义的,或者是用*代表所有tag,而优先级是V D I W E F S,等级越来越高
  V    Verbose
  D    Debug
  I    Info
  W    Warn
  E    Error
  F    Fatal
  S    Silent (supress all output)

例如:adb logcat ActivityManager:I MyApp:D *:S 或者 adb logcat -s ActivityManager:I MyApp:D
上面表达式的最后的元素 *:S ,,是设置所有的标签为”silent”,所有日志只显示有”ActivityManager”和“MyApp”的,用 *:S 的另一个用处是能够确保日志输出的时候是按照过滤器的说明限制的,也让过滤器也作为一项输出写到日志中。

 

具体的logcat详解,可以查看点击这里。

热点排行