在代码中我们经常看见ProtoLog打印的log,如下:
ProtoLog.i(WM_DEBUG_ANIM, "Animation start delayed for %s", mAnimatable);
这种log正常情况不会显示,因此我们需要打开开关,其格式为:
adb shell wm logging enable-text [代码中对应的TAG]
我们这段代码的TAG是WM_DEBUG_ANIM
,因此通过命令adb shell wm logging enable-text WM_DEBUG_ANIM
打开log开关
# 抓取普通的andorid log
adb shell logcat > log.txt
# 仅抓取events log
adb shell logcat -b events > log.txt
# 抓取所有类型log
adb shell logcat -b all > log.txt
# 根据关键字抓取log,-i可以忽略大小,-e可以添加多条关键字,如下:
adb shell logcat -b events | grep -ie "关键log1" -ie "关键log2"> log.txt
events log对应代码的规律是:
events log开头的字段,比如wm_xxx
则对应的代码可以通过 grep 抓取 writeWmxxx 找出是在哪里打印的该events log
例如:
应用走到onresume生命周期的log
wm_on_resume_called: [223605563,com.tencent.mm.ui.LauncherUI,RESUME_ACTIVITY,10]
EventLogTags.writeWmOnResumeCalled(mIdent, getComponentName().getClassName(), reason);
通知cancel的log
notification_canceled: [0|com.tencent.mm|40|null|10218,8,19980,19980,7720,-1,-1,NULL]
EventLogTags.writeNotificationCanceled(canceledKey, reason,
r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now),
rank, count, listenerName);