10 May, 2012

How to: Persistent logging on android device

Android logging system is based on ring buffers located in RAM. Because of that sometimes you can't get the log of an issue (such as unexpected reboot or if you have no connection to adb at that moment). It's especially significant if you test unstable firmware (such as cyanogen nightly).
The following method enables one to overcome this restriction.


We'll employ SL4A once again for collecting android logs to a file for later debugging.
SL4A allows to run script as a service. Thus running the following scripts as a service can help you to get logs. (debug_info directory should be created before using the scripts)

for logcat.log:

cd /sdcard/debug_info; LDIR=`date +%F_%H-%M-%S`; mkdir $LDIR; cd $LDIR;
logcat -v time > logcat.log


for logcat_radio.log:

cd /sdcard/debug_info; LDIR=`date +%F_%H-%M-%S`; mkdir $LDIR; cd $LDIR;
logcat -v time -b radio > logcat_radio.log


for kmsg.log (only for rooted device):

su -c "cat /proc/kmsg > kmsg.log"

About disc space consumption:
On my device the log takes about 650kB every 8 hours.

1 comment:

  1. Do you happen to have an example service Java file you might share?

    ReplyDelete