软件平台:Android11
硬件平台:高通QCS6125
需求:设备即将上线,需要后台实时采集logcat日志,保存到相应目录下,方便app端上传到服务器,从而分析问题。
改动集中在logcat相关部分:
diff --git a/logcat/logcatd.rc b/logcat/logcatd.rc
index e19554a55..2fcdd2181 100755
--- a/logcat/logcatd.rc
+++ b/logcat/logcatd.rc
@@ -39,7 +39,7 @@ on property:logd.logpersistd.enable=true && property:logd.logpersistd=clearsetprop persist.logd.logpersistd ""stop logcatd# logd for clear of only our files in /data/misc/logd
- exec - logd log -- /system/bin/logcat -c -f /data/misc/logd/logcat -n ${logd.logpersistd.size:-256}
+ exec - logd log -- /system/bin/logcat -c -f /data/misc/logd/logcat -n ${logd.logpersistd.size:-30}setprop logd.logpersistd ""# stop logcatd service
@@ -52,7 +52,7 @@ on property:logd.logpersistd.enable=falsestop logcatd# logcatd service
-service logcatd /system/bin/logcatd -L -b ${logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r ${logd.logpersistd.rotate_kbytes:-2048} -n ${logd.logpersistd.size:-256} --id=${ro.build.id}
+service logcatd /system/bin/logcatd -L -b ${logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r ${logd.logpersistd.rotate_kbytes:-2048} -n ${logd.logpersistd.size:-30} --id=${ro.build.id}class late_start#disabled# logd for write to /data/misc/logd, log group for read from log daemon
diff --git a/logcat/logpersist b/logcat/logpersist
index 05b46f047..f37a0b83d 100755
--- a/logcat/logpersist
+++ b/logcat/logpersist
@@ -21,7 +21,7 @@ log_uid=logdlog_tag_property=persist.log.tagdata=/data/misc/logd/logcatservice=logcatd
-size_default=256
+size_default=30buffer_default=allargs="${@}"
这就实现了开机自启动记录logcat,并且设置了每个logcat文件的大小,和一共报错多少个logcat日志文件。
延伸开发:APP可在发现异常时,主动上传该日志,或者拿到问题设备,将日志取出分析。