logcat语法格式:adb logcat []…
如果你的电脑上连接多个设备可以通过adb -s
adb -s 设备号 logcat 抓取指定设备的log
1. adb logcat –help查看logcat命令的帮助信息
> 引用块内容
qiaojiali@qiaojiali-pc:~$ adb logcat --help
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"
adb logcat -d -f /sdcard/mylog.txt 把日志保存到手机上
adb logcat -f /sdcard/log.txt
adb logcat -s WifiHW 抓取所有标签为WifiHW的日志
qiaojiali@qiaojiali-pc:~$ adb logcat -s WifiHW
--------- beginning of system
--------- beginning of main
D/WifiHW ( 744): enter -->wifi_send_command cmd=IFNAME=wlan0 SCAN TYPE=ONLY
D/WifiHW ( 744): [1] get event: IFNAME=wlan0 <3>CTRL-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00 SSID=
D/WifiHW ( 744): [2] get event: IFNAME=wlan0 CTRL-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00 SSID=
D/WifiHW ( 744): enter -->wifi_wait_on_socket buflen=2048
D/WifiHW ( 744): enter -->wifi_ctrl_recv
D/WifiHW ( 744): leave --> reply=OK
D/WifiHW ( 744):
D/WifiHW ( 744): [1] get event: IFNAME=wlan0 <3>CTRL-EVENT-SCAN-STARTED
D/WifiHW ( 744): [2] get event: IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED
D/WifiHW ( 744): enter -->wifi_wait_on_socket buflen=2048
adb logcat | grep Wifi 过滤固定的字符串
qiaojiali@qiaojiali-pc:~$ adb logcat | grep Wifi
D/ActivityThread( 9014): BDC-Calling onReceive: intent=Intent { act=android.net.wifi.WIFI_STATE_CHANGED flg=0x4000010 cmp=com.mediatek.engineermode/.wifi.WifiStateReceiver (has extras) }, receiver=com.mediatek.engineermode.wifi.WifiStateReceiver@2f74a671
D/ActivityThread( 9014): BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=android.net.wifi.WIFI_STATE_CHANGED flg=0x4000010 cmp=com.mediatek.engineermode/.wifi.WifiStateReceiver (has extras) } packageName=com.mediatek.engineermode resultCode=0 resultData=null resultExtras=null}
D/PowerManagerService( 744): isWfdEnabled() mWfdStatus=WifiDisplayStatus{featureState=0, scanState=0, activeDisplayState=0, activeDisplay=null, displays=[], sessionInfo=WifiDisplaySessionInfo: C/O:Client,GId:,Pp:,SId:0,IP:}, return false
D/PowerManagerService( 744): isWfdEnabled() mWfdStatus=WifiDisplayStatus{featureState=0, scanState=0, activeDisplayState=0, activeDisplay=null, displays=[], sessionInfo=WifiDisplaySessionInfo: C/O:Client,GId:,Pp:,SId:0,IP:}, return false
D/WifiService( 744): getWifiServiceMessenger, pid:8600, uid:10062
adb logcat | grep -i wifi 过滤固定的字符串不分大小写
adb logcat | grep “^..Activity” 利用正则表达式过滤日志
logcat过滤log语法:adb logcat tag:priority tag:标签 priority日志优先级
adb logcat WifiHW:D :S 日志是 标签为 WifiHW, 并且优先级 Debug(调试) 等级以上的级别的日志; :S很重要不要忘记
qiaojiali@qiaojiali-pc:~$ adb logcat WifiHW:D *:S
--------- beginning of system
--------- beginning of main
D/WifiHW ( 742): enter -->wifi_send_command cmd=IFNAME=wlan0 SIGNAL_POLL
D/WifiHW ( 742): leave --> reply=RSSI=-50
D/WifiHW ( 742): LINKSPEED=135
D/WifiHW ( 742): NOISE=9999
D/WifiHW ( 742): FREQUENCY=2462
D/WifiHW ( 742):
D/WifiHW ( 742): enter -->wifi_send_command cmd=IFNAME=wlan0 SIGNAL_POLL
D/WifiHW ( 742): leave --> reply=RSSI=-51
D/WifiHW ( 742): LINKSPEED=135
D/WifiHW ( 742): NOISE=9999
D/WifiHW ( 742): FREQUENCY=2462
D/WifiHW ( 742):
D/WifiHW ( 742): enter -->wifi_send_command cmd=IFNAME=wlan0 SIGNAL_POLL
D/WifiHW ( 742): leave --> reply=RSSI=-51
D/WifiHW ( 742): LINKSPEED=135
D/WifiHW ( 742): NOISE=9999
D/WifiHW ( 742): FREQUENCY=2462
D/WifiHW ( 742):
D/WifiHW ( 742): enter -->wifi_send_command cmd=IFNAME=wlan0 SCAN TYPE=ONLY
D/WifiHW ( 742): [1] get event: IFNAME=wlan0 <3>CTRL-EVENT-SCAN-STARTED
adb logcat WifiHW:D dalvikvm:I *:S 同时设置多个过滤器 输出 WifiHW标签的Debug级别以上的和dalvikvm的Info以上级别的日志
qiaojiali@qiaojiali-pc:~$ adb logcat WifiHW:D WifiTrafficPoller:I *:S
--------- beginning of system
--------- beginning of main
D/WifiHW ( 742): enter -->wifi_send_command cmd=IFNAME=wlan0 SCAN TYPE=ONLY freq=2462
D/WifiHW ( 742): [1] get event: IFNAME=wlan0 <3>CTRL-EVENT-SCAN-STARTED
D/WifiHW ( 742): [2] get event: IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED
E/WifiTrafficPoller( 742): TRAFFIC_STATS_POLL true Token 23 num clients 8
E/WifiTrafficPoller( 742): packet count Tx=7123 Rx=18436
E/WifiTrafficPoller( 742): notifying of data activity 1
D/WifiHW ( 742): enter -->wifi_send_command cmd=IFNAME=wlan0 SIGNAL_POLL
D/WifiHW ( 742): leave --> reply=RSSI=-51
D/WifiHW ( 742): LINKSPEED=135
D/WifiHW ( 742): NOISE=9999
D/WifiHW ( 742): FREQUENCY=2462
D/WifiHW ( 742):
日志级别:
– V : Verbose (明细);Log.v(String,String)
– D : Debug (调试);Log.d(String,String)
– I : Info (信息);Log.i(String,String)
例如:Log.i(“MyActivity”,”MyClass.getView()——get item number”+position);
logcat命令获取log:adb logcat logcat将输出如下信息:
I/MyActivity(1577):MyClass.getView()——get item number 1 其中1577是进程号
– W : Warn (警告);Log.w(String,String)
– E : Error (错误);Log.e(String,String)
– F: Fatal (严重错误);
– S : Silent(Super all output) (最高的优先级, 可能不会记载东西);
等级从低到高
加载日志缓冲区 : 使用 adb logcat -b radio;
– Android中的日志缓冲区 :
system缓冲区 - 输出系统组件的log,
radio缓冲区 - 输出通讯系统的log,
events缓冲区 - 输出event模块的log,
main缓冲区 - 所有java层的log,以及不属于上面3层的log;
缓冲区主要给系统组件使用,一般的应用无需关心,应用log都输出到main缓冲区中
adb logcat -t 5 输出最近5行的日志,并且不会阻塞
qiaojiali@qiaojiali-pc:~$ adb logcat -t 5
--------- beginning of main
W/ADB_SERVICES( 6060): read_meminfo() mem_free=148276
W/ADB_SERVICES( 6060): create_subproc ret_fd=20 pid=9519
W/ADB_SERVICES( 6060): LS(75): bound to 'shell:export ANDROID_LOG_TAGS=""""; exec logcat -t 5' via 20
W/ADB_SERVICES( 9519): adb: unable to update oom_score_adj
D/majun ( 1706): reseting
qiaojiali@qiaojiali-pc:~$
adb logcat -c 清空日志缓存信息 : 可以将之前的日志信息清空, 重新开始输出日志信息;
adb logcat -d 将缓存日志输出,输出命令, 之后推出命令, 不会进行阻塞;
adb logcat -f 将log输出到制定的文件中<文件名>。默认为标准的输出
adb logcat -g 打印日志缓冲区的大小并退出
qiaojiali@qiaojiali-pc:~$ adb logcat -g
main: ring buffer is 256Kb (255Kb consumed), max entry is 5120b, max payload is 4076b
system: ring buffer is 256Kb (255Kb consumed), max entry is 5120b, max payload is 4076b
adb logcat -n 设置日志的最大数目,默认是4,需要和-r选项一起使用
adb logcat -r 每时输出日志,默认是16,需要和-f选项一个使用
qiaojiali@qiaojiali-pc:~$ adb logcat -f /storage/sdcard0/log/log.txt -r 10
^C
qiaojiali@qiaojiali-pc:~$
qiaojiali@qiaojiali-pc:~$ adb shell
shell@hct6735m_65_m0:/ $ cd storage/sdcard0/log
shell@hct6735m_65_m0:/storage/sdcard0/log $ ls
log.txt
log.txt.1
log.txt.2
log.txt.3
log.txt.4
shell@hct6735m_65_m0:/storage/sdcard0/log $
在终端执行adb logcat -f /storage/sdcard0/log/log.txt -r 10 把日志输出到log.txt中并且当log.txt大小超过10k的时候就重新生成一个日志文件,当然在平时就可以设置10M,我这里只是为了能够快速看到效果所以设置的一个log只有10k。
adb logcat -v 设置输出格式的日志信息,默认是短暂的格式,
logcat的格式化输出参数说明:
使用-v选项来指定一个支持的输出格式,以下是支持的格式:
brief -显示优先级/标记和过程的PID发出的消息(默认格式)
qiaojiali@qiaojiali-pc:~$ adb logcat -v brief
--------- beginning of system
I/vold ( 231): Vold 3.0 (the awakening) firing up
V/vold ( 231): Detected support for: ext4 vfat
W/Vold ( 231): Tearing down stale mount /mnt/cd-rom
D/vold ( 231): EmulatedVolume(emulated) is newed
V/vold ( 231): ----------------
V/vold ( 231): handleBlockEvent with action 1
D/NetlinkEvent( 231): NL action '1'
D/NetlinkEvent( 231): NL subsystem 'block'
D/NetlinkEvent( 231): NL param 'DEVPATH=/devices/virtual/block/dm-0'
D/NetlinkEvent( 231): NL param 'MAJOR=253'
D/NetlinkEvent( 231): NL param 'MINOR=0'
D/NetlinkEvent( 231): NL param 'DEVNAME=dm-0'
D/NetlinkEvent( 231): NL param 'DEVTYPE=disk'
D/NetlinkEvent( 231): NL param 'NPARTS=0'
process- 只显示PID 输出格式如下:
qiaojiali@qiaojiali-pc:~$ adb logcat -v process
--------- beginning of system
I( 231) Vold 3.0 (the awakening) firing up (vold)
V( 231) Detected support for: ext4 vfat (vold)
W( 231) Tearing down stale mount /mnt/cd-rom (Vold)
D( 231) EmulatedVolume(emulated) is newed (vold)
V( 231) ---------------- (vold)
V( 231) handleBlockEvent with action 1 (vold)
D( 231) NL action '1' (NetlinkEvent)
D( 231) NL subsystem 'block' (NetlinkEvent)
tag-只显示优先级/标记 输出格式如下:
qiaojiali@qiaojiali-pc:~$ adb logcat -v tag
--------- beginning of system
I/vold : Vold 3.0 (the awakening) firing up
V/vold : Detected support for: ext4 vfat
W/Vold : Tearing down stale mount /mnt/cd-rom
D/vold : EmulatedVolume(emulated) is newed
V/vold : ----------------
V/vold : handleBlockEvent with action 1
raw-显示原始的日志信息,没有其他元数据字段 输出格式如下:
qiaojiali@qiaojiali-pc:~$ adb logcat -v raw
--------- beginning of system
Vold 3.0 (the awakening) firing up
Detected support for: ext4 vfat
Tearing down stale mount /mnt/cd-rom
EmulatedVolume(emulated) is newed
----------------
handleBlockEvent with action 1
NL action '1'
NL subsystem 'block'
NL param 'DEVPATH=/devices/virtual/block/dm-0'
NL param 'MAJOR=253'
NL param 'MINOR=0'
NL param 'DEVNAME=dm-0'
NL param 'DEVTYPE=disk'
NL param 'NPARTS=0'
time-调用显示人日期,时间,优先级/标签和过程PID发出消息 输出格式如下:
qiaojiali@qiaojiali-pc:~$ adb logcat -v time
--------- beginning of system
01-02 00:50:31.834 I/vold ( 231): Vold 3.0 (the awakening) firing up
01-02 00:50:31.834 V/vold ( 231): Detected support for: ext4 vfat
01-02 00:50:31.860 W/Vold ( 231): Tearing down stale mount /mnt/cd-rom
01-02 00:50:31.908 D/vold ( 231): EmulatedVolume(emulated) is newed
01-02 00:50:31.957 V/vold ( 231): ----------------
01-02 00:50:31.957 V/vold ( 231): handleBlockEvent with action 1
threadtime-调用显示日期,时间,优先级,标签以及PID,TID线程发出的消息,输入格式如下:
qiaojiali@qiaojiali-pc:~$ adb logcat -v threadtime
--------- beginning of system
01-02 00:50:31.834 231 231 I vold : Vold 3.0 (the awakening) firing up
01-02 00:50:31.834 231 231 V vold : Detected support for: ext4 vfat
01-02 00:50:31.860 231 231 W Vold : Tearing down stale mount /mnt/cd-rom
01-02 00:50:31.908 231 231 D vold : EmulatedVolume(emulated) is newed
01-02 00:50:31.957 231 252 V vold : ----------------
01-02 00:50:31.957 231 252 V vold : handleBlockEvent with action 1
long -显示所有元数据字段与空白行和单独的消息
输出格式如下:
qiaojiali@qiaojiali-pc:~$ adb logcat -v long
--------- beginning of system
[ 01-02 00:50:31.834 231: 231 I/vold ]
Vold 3.0 (the awakening) firing up
[ 01-02 00:50:31.834 231: 231 V/vold ]
Detected support for: ext4 vfat
[ 01-02 00:50:31.860 231: 231 W/Vold ]
Tearing down stale mount /mnt/cd-rom
[ 01-02 00:50:31.908 231: 231 D/vold ]
EmulatedVolume(emulated) is newed