1、查看adb logcat帮助信息

C:\Users\000>adb logcat --helpUsage: 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"

2、解析选项

– “-s”选项 : 设置输出日志的标签, 只显示该标签的日志;

–”-f”选项 : 将日志输出到文件, 默认输出到标准输出流中;

–”-r”选项 : 按照每千字节输出日志, 需要 -f 参数;

–”-n”选项 : 设置日志输出的最大数目, 需要 -r 参数;

–”-v”选项 : 设置日志的输出格式, 注意只能设置一项;

–”-c”选项 : 清空所有的日志缓存信息;

–”-d”选项 : 将缓存的日志输出到屏幕上, 并且不会阻塞;

–”-t”选项 : 输出最近的几行日志, 输出完退出, 不阻塞;

–”-g”选项 : 查看日志缓冲区信息;

–”-b”选项 : 加载一个日志缓冲区, 默认是 main, 下面详解;

–”-B”选项 : 以二进制形式输出日志;

3、输出指定标签的日志

方式1:设置默认的过滤器,-s选项+标签名
adb logcat -s TAG标签名 TAG标签名
如:

adb logcat -s VideoFragment VLCVideoPlayerActivity

方式2:自定义过滤器,指定日志级别
LEVEL可以选择:

– V : Verbose (明细);
– D : Debug (调试);
– I : Info (信息);
– W : Warn (警告);
– E : Error (错误);
– F: Fatal (严重错误);
– S : Silent(Super all output) (最高的优先级, 可能不会记载东西);

TAG:X 的作用为: 输出标签为TAG的log级别大于X的信息,例如:

adb logcat VideoFragment:D

输出 VideoFragment的D 和D级别以上的log,包括 D, I, W, E,F, S
注意:
(1)可以指定多个[TAG:LEVEL ]
(2) level : S 表示为不输出该标签的日志,应为没有大于S级别的日志了
(3) [TAG:LEVEL ] 不会影响其他标签的日志, 所以如果要屏蔽其他log请使用 *:S,例如:

adb logcat VideoFragment:D VLCVideoPlayerActivity:D *:S

方式3:使用管道过滤日志
linux系统下:

adb logcat | grep -e "VideoFragment\|VLCVideoPlayerActivity"adb logcat | grep -e "VideoFragment|VLCVideoPlayerActivity"adb logcat |grep -e VideoFragment -e VLCVideoPlayerActivity

windows系统下:
多个条件直接用空格

adb logcat | findstr "VideoFragment VLCVideoPlayerActivity"

4、输出日志信息到文件

方式1:-f选项

adb logcat -f /sdcard/log.txt 

方式2:输出重定向

adb logcat > /sdcard/log.txt  

后台执行

logcat -f /sdcard/log.txt &   #这里的&符号表示后台执行,不能少

注意合适的时候需要停止掉以上命令,必须有多个logcat在写同一个文件。
停止方法:

adb shell kill -9 <logcat_pid> 

其中logcat_pid 通过 如下命令获取

adb shell ps | grep logcat          # linux 平台adb shell ps | findstr "logcat"    #Windows平台

5、-v 日志常用输出格式

1、“tag”格式 : ” 优先级 / 标签 : 日志信息”,例如:

C:\Users\000>adb logcat -v tag -s VideoFragmentD/VideoFragment: ====== onCreateD/VideoFragment: =======bindVideoPlayerServiceD/VideoFragment: UpdateAdapterTask doInBackgroundD/VideoFragment: ====== onStartD/VideoFragment: UpdateAdapterTask onPostExecuteD/VideoFragment: =====UpdateAdapterTask notifyDataSetChangedD/VideoFragment: =====  PlayerService onServiceConnected

2、“time”格式 : “日期 时间 优先级 / 标签 (进程ID) : 进程名称 : 日志信息 “, 例如:

C:\Users\000>adb logcat -v time -s VideoFragment04-25 15:04:39.591 D/VideoFragment( 5859): ====== onCreate04-25 15:04:39.601 D/VideoFragment( 5859): =======bindVideoPlayerService04-25 15:04:39.621 D/VideoFragment( 5859): UpdateAdapterTask doInBackground04-25 15:04:39.621 D/VideoFragment( 5859): ====== onStart04-25 15:04:39.641 D/VideoFragment( 5859): UpdateAdapterTask onPostExecute04-25 15:04:39.641 D/VideoFragment( 5859): =====UpdateAdapterTask notifyDataSetChanged04-25 15:04:39.781 D/VideoFragment( 5859): =====PlayerService onServiceConnected

6、日志缓冲区

C:\Users\000>adb shellroot@rk3288:/ # ll /dev/logcrw-rw-rw- root     log       10,  46 2016-04-25 10:50 events #事件相关的日志信息crw-rw-rw- root     log       10,  47 2016-04-25 10:50 main #默认的缓冲区crw-rw-rw- root     log       10,  45 2016-04-25 10:50 radio #广播电话相关的日志信息crw-rw-rw- root     log       10,  44 2016-04-25 10:50 system #与系统相关的日志信息

查看日志缓冲区信息:

C:\Users\000>adb logcat -g/dev/log/main: ring buffer is 256Kb (40Kb consumed), max entry is 5120b, max payload is 4076b/dev/log/system: ring buffer is 256Kb (11Kb consumed), max entry is 5120b, max payload is 4076b

清空日志缓冲区:

C:\Users\000>adb logcat -cC:\Users\000>adb logcat -g/dev/log/main: ring buffer is 256Kb (0Kb consumed), max entry is 5120b, max payload is 4076b/dev/log/system: ring buffer is 256Kb (0Kb consumed), max entry is 5120b, max payload is 4076b

更多相关文章

  1. android Manifest.xml选项-android:ConfigChanges
  2. android实践项目一实现简单的验证码和spinner下拉选项效果
  3. 重定向android log
  4. Android(安卓)编程下通过 zipalign 对 APK 文件进行优化
  5. Android(安卓)tabhost让选中项加上背景图
  6. Android(安卓)Studio 修改 Logcat 颜色
  7. 理解Android中垃圾回收日志信息
  8. android读取工程里文件并显示在界面
  9. Android(安卓)sd卡log日志

随机推荐

  1. 小程序「答题小助手」已经上线,欢迎你来答
  2. 七乐章
  3. 漫谈容器监控
  4. 容器组织服务docker-compose
  5. 7.Cisco vWLC在VMware exsi下的安装与组
  6. SQL存储过程的详细用法,不信你看不懂
  7. 一个ftp传输文件引发的思考
  8. 实现多文件上传| MVC与依赖注入的原理
  9. 保护隐私减少广?告骚扰小技巧-微*信篇
  10. 5G进小区竟被物业索要30万“入场费”,技术