Android --- logcat 打印日志、设置缓存大小、过滤等

一、示例:

setprop persist.log.tag -G 
setprop persist.log.tag V
setprop persist.log.tag S
setprop persist.log.tag.APP_A V
setprop persist.log.tag.App_B V
setprop persist.log.tag.App_C V
setprop persist.log.tag.AndroidRuntime V

Android log 通过系统属性persist.log.tag persist.log.tag.ABC 决定相关log的指定等级及以上才可以写入,ABC是指某个tag,TAG长度不能太长。

二、设置系统属性:

1.设置log日志缓存大小

setprop persist.log.tag -G 

2.使能所有log tag 输出,设置所有log V等级及以上才能输出

   setprop persist.log.tag V

3.禁止所有log tag 的输出,设置所有log, S等级及以上的log才能输出,S等级最高,V等级最低

setprop persist.log.tag S

4.禁止log tag 为 sss的输出,设置log tag 为 sss 的S等级及以上才能输出

   setprop persist.log.tag.sss S 

5.使log tag 为 APP_A 的输出,设置log tag 为 APP_A 的V等级及以上能输出

  setprop persist.log.tag.APP_A V 

三、打印日志相关:

1.当你的日志打印超出缓存的时候

系统报:If you have enabled significant logging, look into using the -G option to increase log buffer sizes.

输入以下内容

adb shell logcat -G 200MB

2.查看缓存区大小

logmsmnile_au:/ $ logcat -g
main: ring buffer is 256 KiB (250 KiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 256 KiB (41 KiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (4 KiB consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (97 KiB consumed), max entry is 5120 B, max payload is 4068 B

3.清空log

有时候打印某APP log 的时候,发现一直刷,停不下来

logcat -c

4.输出APP_A的log

adb shell logcat -s APP_A

5.将打印的log自动写入本地文件中

adb logcat > D:\1\11.txt

结束日志写入:ctrl + c

6.打印App_A的日志,并过滤Wifi字段

logcat -s App_A | grep Wifi

7.打印App_A的日志,并过滤Wifi Info字段

logcat -s App_A | grep "Wifi Info"

8.打印App_A的日志,过滤多个字段(abc、def)

logcat -s App_A | grep -e abc -e def

9.查看内存使用情况

adb shell top

10.打印crash的log

adb shell logcat -s AndroidRuntime

说明:等级有VERBOSE、DEBUG、INFO,WARN、ERROR、FATA、SILENT

猜你喜欢

转载自blog.csdn.net/qq_43290288/article/details/129277535