1.速查

  1. $adb logcat -g     //打印和缓冲区使用情况
  1. $adb logcat -c main //清除main缓存区
  1. $adb logcat -v threadtime -f /data/camera.log | grep -Ei "camera | daemon"
  • -v threadtime 输出格式 ,默认是 brief
  • -f /data/camera.log 保存到文件
  • grep -Ei "camera | daemon" 是过滤,-i是忽略大小写,E是指定多个过滤字符串,logcat的自代过滤器(tag:优先级)不好用!

2.先要知道的第一件事

  android把log输出到不同的缓冲区中,常见的几个log缓冲区:

缓冲区 描述
radio 输出通信系统的log
system 输出系统组件的log
crash 崩溃日志
events 输出event模块的log
main

所有java层的log,以及不属于上面3层的log

all

全部

3.先要知道的第二件事

  • 有两个logcat : adb logcat 与 adb shell logcat 命令不同,使用场景不同。
  • logcat有很多参数:adb logcat --help 可查看。

4.参数详解

第1个参数:打印各日志缓冲区的大小并退出

  1. $adb logcag -g

  结果如下:

  1. main: ring buffer is 256Kb (235Kb consumed), max entry is 5120b, max payload is 4076b
  2. system: ring buffer is 256Kb (238Kb consumed), max entry is 5120b, max payload is 4076b
  3. crash: ring buffer is 256Kb (242Kb consumed), max entry is 5120b, max payload is 4076b

第2个参数:打印某个缓冲区日志

  1. $adb logcat -b system

默认是 -b main -b system -b crash.

第3个参数:设置log的输出格式

  1. $adb logcat -v threadtime

threadtime是输出格式,常见输出格式:

格式

说明

brief 显示优先级/标记和过程的PID发出的消息(默认格式)
process 只显示PID
tag 只显示优先级/标记
raw 显示原始的日志消息,没有其他元数据字段
time 调用显示日期、时间、优先级/标签和过程的PID发出消息
thread 过滤线程
threadtime 调用显示日期、时间、优先级、标签以及PID TID线程发出的消息
long 显示所有元数据字段与空白行和单独的消息

第4个参数:设置过滤器[ tag名:优先级 ] ,默认是[*:I]

  1. $adb logcat ActivityManager:I YourApp:D *:S

这个命令指定了3个过滤器:

  • ActivityManager:I
  • YourApp:D
  • *:S

其中ActivityManager和YourApp是tag,I 、D 、S是优先级。优先级表如下:从低到高

V Verbose(最低优先级)
D Debug
I Info
W Warning
E Error
F Fatal
S Silent

再来一个例子:

  1. $adb logcat *:

第5个参数:输出到文件(注意文件保存在设备上)

  1. $adb logcat -v threadtime -f /data/camera.log

5.详解,有些参数可以合并一起,最好分开,如 -v xxx -f xxx

  1. Usage: logcat [options] [filterspecs]
  2. options include:
  3. -s Set default filter to silent.
  4. Like specifying filterspec '*:s'
  5. -f <filename> Log to file. Default to stdout
  6. -r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f
  7. -n <count> Sets max number of rotated logs to <count>, default 4
  8. -v <format> Sets the log print format, where <format> is one of:
  9.  
  10. brief process tag thread raw time threadtime long
  11.  
  12. -c clear (flush) the entire log and exit
  13. -d dump the log and then exit (don't block)
  14. -t <count> print only the most recent <count> lines (implies -d)
  15. -t '<time>' print most recent lines since specified time (implies -d)
  16. -T <count> print only the most recent <count> lines (does not imply -d)
  17. -T '<time>' print most recent lines since specified time (not imply -d)
  18. count is pure numerical, time is 'MM-DD hh:mm:ss.mmm'
  19. -g get the size of the log's ring buffer and exit
  20. -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio',
  21. 'events', 'crash' or 'all'. Multiple -b parameters are
  22. allowed and results are interleaved. The default is
  23. -b main -b system -b crash.
  24. -B output the log in binary.
  25. -S output statistics.
  26. -G <size> set size of log ring buffer, may suffix with K or M.
  27. -p print prune white and ~black list. Service is specified as
  28. UID, UID/PID or /PID. Weighed for quicker pruning if prefix
  29. with ~, otherwise weighed for longevity if unadorned. All
  30. other pruning activity is oldest first. Special case ~!
  31. represents an automatic quicker pruning for the noisiest
  32. UID as determined by the current statistics.
  33. -P '<list> ...' set prune white and ~black list, using same format as
  34. printed above. Must be quoted.
  35.  
  36. filterspecs are a series of
  37. <tag>[:priority]
  38.  
  39. where <tag> is a log component tag (or * for all) and priority is:
  40. V Verbose
  41. D Debug
  42. I Info
  43. W Warn
  44. E Error
  45. F Fatal
  46. S Silent (supress all output)
  47.  
  48. '*' means '*:d' and <tag> by itself means <tag>:v
  49.  
  50. If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.
  51. If no filterspec is found, filter defaults to '*:I'
  52.  
  53. If not specified with -v, format is set from ANDROID_PRINTF_LOG or defaults to "brief"

adb logcat教程的更多相关文章

  1. Android ADB命令教程二——ADB命令详解

    Android ADB命令教程二——ADB命令详解 转载▼ 原文链接:http://www.tbk.ren/article/249.html       我们使用 adb -h 来看看,adb命令里面 ...

  2. adb logcat 基本用法

    入门android ,至少需要了解 adb 吧,那么打 log 也是必不可少的了. 下面简单介绍一下 adb logcat 基本用法: Usage: logcat [options] [filters ...

  3. 如何用adb logcat保存日志

    //将log 保存到当前目录下 adb logcat -v time >a.log //log过滤 adb logcat | grep MyAppName //清除log adb logcat ...

  4. adb logcat 命令

    转自:http://blog.csdn.net/tumuzhuanjia/article/details/39555445 1. 解析 adb logcat 的帮助信息 在命令行中输入 adb log ...

  5. dos保存adb logcat读取的Android信息

    /***************************************************************************** * dos保存adb logcat读取的A ...

  6. 如何过滤 adb logcat 输出

    对原作者表示感谢,转自博客:http://www.otechu.me/zh/2011/12/filtering-adb-logcat-output/ 本文介绍如何在 shell 命令行中过滤 adb ...

  7. adb logcat调试中常用的命令介绍

    Android日志系统提供了记录和查看系统调试信息的功能.日志都是从各种软件和一些系统的缓冲区中记录下来的,缓冲区可以通过 logcat 命 令来查看和使用. adb logcat 命令格式 : ad ...

  8. adb logcat 查看日志

    使用 logcat 命令 查看和跟踪系统日志缓冲区的命令logcat的一般用法是: [adb] logcat [<option>] ... [<filter-spec>] .. ...

  9. adb logcat命令查看并过滤android输出log

    cmd命令行中使用adb logcat命令查看android系统和应用的log,dos窗口按ctrl+c中断输出log记录. logcat日志中的优先级/tag标记: android输出的每一条日志都 ...

随机推荐

  1. Entity Framework 6 Code First 实践系列(1):实体类配置-根据依赖配置关系和关联

    EF实体类的配置可以使用数据注释或Fluent API两种方式配置,Fluent API配置的关键在于搞清实体类的依赖关系,按此方法配置,快速高效合理.为了方便理解,我们使用简化的实体A和B以及A.B ...

  2. hadoop eclipse插件生成

    hadoop eclipse插件生成 做了一年的hadoop开发.还没有自动生成过eclipse插件,一直都是在网上下载别人的用,今天有时间,就把这段遗憾补回来,自己生成一下,废话不说,開始了. 本文 ...

  3. iptables apache2

    Apache2 iptables 安装指令:sudo apt-get install apache2 2.产生的启动和停止文件是:/etc/init.d/apache2 3.启动:sudo apach ...

  4. weblogic 修改控制台console访问路径 url

    出于安全的考虑需要对weblogic的console进行屏避,或者修改默认的访问路径,主要有两种方法:(这里针对weblogic8.1) 一.进入默认的控制台,例如“localhost/console ...

  5. JavaScript算法题(一) && 数组reduce使用

    可参考Array.reduce用法 1. 请编写getMissingElement函数,返回给定数组中缺少的元素(数组里的元素为0~9,只会缺失一个). Example: getMissingElem ...

  6. 用redis实现动态时间段内统计排序

    问题描述 需要根据某类数据在动态时间段内的统计值对这些数据进行排名.例如按过去24小时内点赞数排名的帖子,每隔一小时计算一次结果.以下描述均针对这个例子展开. 解决思路 针对这种问题,我的第一反应是直 ...

  7. MapReduce ChainMapper/ChainReducer

    The ChainMapper class allows to use multiple Mapper classes within a single Map task.  The ChainRedu ...

  8. 从零开始徒手撸一个vue的toast弹窗组件

    相信普通的vue组件大家都会写,定义 -> 引入 -> 注册 -> 使用,行云流水,一气呵成,但是如果我们今天是要自定义一个弹窗组件呢? 首先,我们来分析一下弹窗组件的特性(需求): ...

  9. python数据分组运算

    摘要: pandas 的 GroupBy 功能可以方便地对数据进行分组.应用函数.转换和聚合等操作.   # 原作者:lionets GroupBy 分组运算有时也被称为 “split-apply-c ...

  10. Linux:NFS文件共享问题重新认识

    之前也搭建过nfs,服务器之间目录里面的文件同享也一直正常.今天有现场反映,搭建nfs后,客户端文件在服务器端看不见. 在我之前的认识里,服务器端搭建好并启动nfs服务,客户端mount后,客户端.服 ...