2

Is it possible to retrieve a logcat from before a system crash after the phone recovers? I.e. my phone is running normally, then it crashes and reboots, and I want to view the logs when it recovers to try to determine what caused the crash. I can't find any way to view logcat in anything other than realtime, except to have a terminal emulator running and execute logcat -f logcat.txt V, then just leave it running forever. That could build up a massive file that eats up all my storage.

I can't believe there's no way to view a crash report, I just can't figure out how.

1 Answer 1

3

Unfortunately logcat does not survive a hard reboot because the logs are stored in circular buffers in memory, and are never actually written to storage. Your solution to leave a terminal session running may work, but as you said may grow the file uncontrollably, and during a reboot it may corrupt the output file. I would suggest adding the -r and -n switches so that only the most recent entries are written:

logcat -r 1024 -n 10 -f /sdcard/logcat.txt &

This limits the logs to 10 files named "logcat.txt", "logcat.txt.2", etc., each 1MB in size. When that limit is reached, it will overwrite the first file, and so on.

You may also want to look into /proc/last_kmsg file, which stores kernel logs just prior to the last reboot. Use cat /proc/last_kmsg > /sdcard/last_kmsg.txt command to write its contents to a file on your storage.

5
  • The first thing is probably the best option. Is there still risk of the last file getting corrupted on the hard crash? Also, will the most recent log always be called logcat.txt, with the older logs incrementing their suffix, or will the newest log just overrwrite the oldest and keep the same name?
    – ewok
    Commented Mar 27, 2015 at 18:32
  • 1
    Newest one will always be called "logcat.txt", and the others will be named .1, .2, and .3. And yes, there is always the risk of the file currently being written to getting corrupted on crash.
    – Chahk
    Commented Mar 27, 2015 at 18:37
  • ok new issue. I kicked this off from an adb shell, which is nice because it runs in the background. but I accidentally put the output files on my internal sdcard instead of external and I can't figure out how to kill the process. I closed the shell but the process is still running
    – ewok
    Commented Mar 27, 2015 at 18:38
  • also, it's cycling at ~16KB and only storing 5 files
    – ewok
    Commented Mar 27, 2015 at 18:40
  • 1
    In adb shell top command will give you all currently running processes. Try killing the process named "logcat" with owner "shell". The syntax is adb shell kill NNNN where "NNNN" is the process ID (1st column in top.) Also, rebooting the device will definitely stop it :)
    – Chahk
    Commented Mar 27, 2015 at 18:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .