Record Android logs infinitely by redirecting them to a file
In certain situations, logcat and/or kernel logs cannot provide us with long enough events history in order for debugging to begin. Due to the Android limitation logs are being stored for an only certain amount of time, but there is a method around this.
There is a possibility of redirecting the logcat and any other events to a file. The biggest advantage is that device does not have to be connected to a host PC in order to carry on storing events.
After connecting the device to host PC and ensuring the USB debugging is on use terminal to access the shell.
$ adb shell
Now redirect the logs to internal storage:
$ logcat –v time * > /sdcard/logcat.txt &
This command with ‘&’ at the end allows the process to run in the background. USB connection is no longer required. Logs will be stored in the root of /sdcard.
The same technique can be used with any other events, for example, kernel logs:
cat /proc/kmsg > /sdcard/kernel_log.txt &
Now we don’t have to worry anymore that anything will be missed, the device will keep on redirecting logs until its rebooted.
If you have any suggestions I am open for opinions.