ProtoLog开关
在代码中我们经常看见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开关
logcat抓取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对应代码的规律是:
events log开头的字段,比如wm_xxx
则对应的代码可以通过 grep 抓取 writeWmxxx 找出是在哪里打印的该events log
例如:
应用走到onresume生命周期的logwm_on_resume_called: [223605563,com.tencent.mm.ui.LauncherUI,RESUME_ACTIVITY,10]
文章来源:https://www.toymoban.com/news/detail-810385.html
EventLogTags.writeWmOnResumeCalled(mIdent, getComponentName().getClassName(), reason);
通知cancel的lognotification_canceled: [0|com.tencent.mm|40|null|10218,8,19980,19980,7720,-1,-1,NULL]
文章来源地址https://www.toymoban.com/news/detail-810385.html
EventLogTags.writeNotificationCanceled(canceledKey, reason,
r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now),
rank, count, listenerName);
到了这里,关于android 常规log的查看与抓取的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!