常用例子

单个 Tag 过滤

  1. //<tag>[:priority]
  2. //后面优先级不区分大小写,参数区分
  3. adb logcat -s Xposed
  4. //或者
  5. adb logcat Xposed *:s

多个 Tag 过滤

  1. //<tag>[:priority]
  2. adb logcat ActivityManager:I MyApp:D *:S

grep 关键字过滤

  1. adb logcat |grep keywords

输出到文件

  1. adb logcat -f /sdcard/log.txt -n2 -r20 log.txt

log.txt
log.txt.1
log.txt.2
后面会会循环输出达到其中3个文件 -r 是大小

logcat

  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. brief process tag thread raw time threadtime long
  10. -c clear (flush) the entire log and exit
  11. -d dump the log and then exit (don't block)
  12. -t <count> print only the most recent <count> lines (implies -d)
  13. -g get the size of the log's ring buffer and exit
  14. -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio'
  15. or 'events'. Multiple -b parameters are allowed and the
  16. results are interleaved. The default is -b main -b system.
  17. -B output the log in binary
  18. filterspecs are a series of
  19. <tag>[:priority]
  20. where <tag> is a log component tag (or * for all) and priority is:
  21. V Verbose
  22. D Debug
  23. I Info
  24. W Warn
  25. E Error
  26. F Fatal
  27. S Silent (supress all output)
  28. '*' means '*:d' and <tag> by itself means <tag>:v
  29. If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.
  30. If no filterspec is found, filter defaults to '*:I'
  31. If not specified with -v, format is set from ANDROID_PRINTF_LOG
  32. or defaults to "brief"

参考文档

https://www.cnblogs.com/JianXu/p/5468839.html