adb logcat 查看日志

2016-10-17  本文已影响0人  yoosir

使用 logcat 命令
查看和跟踪系统日志缓冲区的命令logcat的一般用法是:

[adb] logcat [<option>] ... [<filter-spec>] ...

调用方式在终端窗口中输入:

adb logcat

//如果指定设备
adb -s [设备ID] logcat

1. 解析 adb logcat 的 帮助信息

//输入命令
adb logcat -help
//输出结果
logcat: invalid option -- h
Unrecognized Option
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)
  -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'
  -g              get the size of the log's ring buffer and exit
  -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio',
                  'events', 'crash' or 'all'. Multiple -b parameters are
                  allowed and results are interleaved. The default is
                  -b main -b system -b crash.
  -B              output the log in binary.
  -S              output statistics.
  -G <size>       set size of log ring buffer, may suffix with K or M.
  -p              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> ...' set prune white and ~black list, using same format as
                  printed above. Must be quoted.

filterspecs 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>:v

If 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_LOG
or defaults to "brief"

选项解析 :

** Log 优先级是下面的字符,顺序是从低到高 **:

输出指定标签内容

octopus@octopus:~$ adb logcat -s System.out  
--------- beginning of /dev/log/system  
--------- beginning of /dev/log/main  
I/System.out(22930): GSM -91  
I/System.out(22930): SignalStrength issssssssss : -91  
I/System.out(22930): GSM -91  
I/System.out(22930): SignalStrength issssssssss : -91  
I/System.out(22930): Supervisor Thread  
I/System.out(22930): Got run mode 

输出日志信息到文件

octopus@octopus:~$ adb logcat -f /sdcard/log.txt

****过滤指定等级日志****


// 输出 显示 Error 以上级别的日志
octopus@octopus:~$ adb logcat *:E  
  
Note: log switch off, only log_main and log_events will have logs!  
--------- beginning of /dev/log/main  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
E/dalvikvm(  756): GC_CONCURRENT freed 1809K, 27% free 19489K/26695K, paused 16ms+5ms, total 109ms  
E/WifiHW  (  441): wifi_send_command : SCAN ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
E/dalvikvm(  756): GC_CONCURRENT freed 1820K, 27% free 19490K/26695K, paused 16ms+3ms, total 102ms  
E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  

过滤指定标签等级日志 :

// **命令含义** : 输出10条日志, 日志是 标签为 WifiHW, 并且优先级 Debug(调试) 等级以上的级别的日志;
//**注意 *:S** : 如果没有 *S 就会输出错误,*S 代表白名单;

octopus@octopus:~$ adb logcat 10 WifiHW:D *:S  
  
Note: log switch off, only log_main and log_events will have logs!  
--------- beginning of /dev/log/main  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  

可以同时设置多个过滤器

使用 命令:
adb logcat WifiHW:D dalvikvm:I *:S

输出 WifiHW 标签 的 Debug 以上级别 和 dalvikvm 标签的 Info 以上级别的日志;
上一篇 下一篇

猜你喜欢

热点阅读