[转载]起动service保存android系统log( logcat服务)

原文链接:http://www.myexception.cn/android/1904013.html

启动service保存android系统log

作为android开发工程师,出现了BUG是否苦于没有log而苦恼万分呢,以下敝人提供一套自动保存log的方法,供大家借鉴学习:

首先,在产品目录的init.XXX.rc文件中,添加相应的service,

# start log service
 start logd
on property:service.logcat.enable=1
    start logcat_service

on property:service.logcat.enable=0
    stop logcat_service

# log services
service logcat_service /system/bin/logcat -b system -b events -b main -b radio -k -n 10 -v threadtime -r5000 -f /data/Logs/Log.0/logcat.log
    user root
    group log system
    class main
       disabled

service logd /system/bin/sh /system/bin/logd.sh
    user system
    group log
    oneshot

 

 

然后,在目标平台的system/bin下添加脚本文件logd.sh,处理存储的log日志,以及设置属性,开启logcat_service,

#!/system/bin/sh

#
# Global folder & cmd params
#

OUTPUT_DIR=/data
LOG=Logs
index=2

LOG_DIR[0]=$OUTPUT_DIR/$LOG/Log.0
LOG_DIR[1]=$OUTPUT_DIR/$LOG/Log.1
LOG_DIR[2]=$OUTPUT_DIR/$LOG/Log.2

RM=rm
MV="mv"
MKDIR=mkdir
UMASK=umask


# set default permission 0775
$UMASK 002

# Init the three folders

i=0
while [ "$i" -le "$index" ]
do
$MKDIR -p ${LOG_DIR[$i]}
i=$(($i+1))
done

# Transfer the three folders
((i=$index-1))
$RM -r ${LOG_DIR[$index]}/*
while [ "$i" -ge "0" ]
do
$MV ${LOG_DIR[$i]}/* ${LOG_DIR[$i+1]}
i=$(($i-1))
done
$RM -r ${LOG_DIR[0]}/*

# start logcat service
setprop service.logcat.enable 1

mkdir /data/www
cp -R /system/var/www/    /data/
ln -s /storage/external/ /data/www/sdcard

 

posted @ 2016-06-11 15:12  sndnvaps  阅读(3136)  评论(0编辑  收藏  举报