Can I get logcat logs after phone reboots?
Asked Answered
O

5

25

I'm testing an android application with a long running service. I'm using Eclipse and have the usb cord hooked up with the phone sitting next to me. Since it's a long ongoing service, I do some other work while it runs and check the logcat logs every once in a while to make sure everything is going as expected.

A few minutes ago I noticed the phone rebooting. I think it's done this before as it would explain some weird application behavior. I quickly switched over to Eclipse to see what happened and found that the logcat log was (it seems) cleared during the reboot. So there's no log of whether my app crashed (and took down the phone?!) or if there was some other problem that took down the phone and my app.

Is there anyway I can find out what happened? This is a development phone, so I don't know if it reboots/crashes often on its own, or only while my app is running. It's a Motorola Droid running Firmware version 2.1-update1.

Thanks for your help.

Override answered 12/8, 2010 at 14:55 Comment(3)
#3361730 If you know how to open a console to your phone(sorry I dont) then this might help you out. You can add the -f parameter and specify a file to have all the logs piped to so that you can go get it after the reboot.Adlai
May not be particular to your situation, but in case it helps somebody... I've found using up too many systems resources can cause spurious reboots which are difficult to track down via logs. For instance, if you have something generating intents but you aren't listening to them (for instance, if your listening thread gets blocked.)Weeping
Possible duplicate of Android: How to get kernel logs after kernel panic?Aerology
S
17

I don't know of any way to do this. However, you could start up logcat in adb with adb logcat -v time > logcat.txt and then run your app again. If it crashes a second time, then you can go look at the output in logcat.txt on your machine.

Slur answered 12/8, 2010 at 15:11 Comment(8)
Note that file writes are buffered, so the very last words before rebooting may not be flushed to the file.Bruce
@adamk: Also a good point. Is there a cleaner way to do this (I'm guessing adb bugreport)?Slur
@eldarerathis: you guessed right :) - I used it a couple of times, and it proved useful. BTW - running adb shell logcat -f file.txt may be better (in the buffering sense) than just piping using the shell, but it's really just a guess.Bruce
I was able to catch a crash, and this line from the log: 08-12 11:22:50.568 E/mdm_panicd( 1002): Modem has reset, reboot system! Thanks! This has helped.Override
@adamk: I'll have to test that sometime. I've got Unix bash syntax so stuck in my head that I just automatically use > without even thinking about it. Not to say that I don't love bash, of course.Slur
adb shell logcat -f file.txt lead to couldn't open output file: Read-only file system ;( It's my private phone. Dont want to route it.Olodort
@OneWorld: Try taking shell out of the command. adb shell logcat will try to run logcat on the phone and save the output file to the phone's filesystem. Executing it without shell should cause logcat to run on your computer instead. If you want to save the log to your phone then you could try an absolute path to a writable directory - maybe adb shell logcat -f /sdcard/file.txt or something.Slur
Thanks for this. I just used this with great success to work out why the emulator, when running 4.4.2, was rebooting every time I tried to run my application. It captured a SIGABRT event to do with SensorService. After I disabled the use of internal sensors in my application, it is now running on the emulator just fine.Constituent
B
16

You can use adb bugreport, which should contain some information regarding a spurious reboot - for example, a kernel panic, last logcat entries etc.

Be warned, though: this tool outputs immense amounts of information, so you'll have to dig deep to find what you need.

Bruce answered 12/8, 2010 at 16:56 Comment(3)
Wow. That gave me 20,000+ lines. I'm sure it's great information, though I don't know what to do with it!Override
@Scott: I'd start by searching inside your app's package id, log tags etc. to see if there's anything related to your app.Bruce
I'm looking through it now. I'm not seeing anything from before the reboot, though. Maybe I waited too long? It's been about two hours since the last reboot.Override
G
1

On newer android versions you can try the following command

adb logcat -b all -L

This should output the contents of '/sys/fs/pstore/console-ramoops-0'.

Note: This command does NOT work if your OS still uses /proc/last_kmsg for its last reboot logs.

Guilt answered 1/2 at 17:12 Comment(0)
E
0

I have run into this problem as well. It should be possible to write an app that continuously saves the logcat output to a file on the SD card. There are apps on the market that display the logcat output, so I know it is accessible from within an application.

@djv, I wasn't able to find a /log directory in either root or /data on my phone.

Elea answered 12/8, 2010 at 15:25 Comment(3)
Logs aren't flushed to the disk in Android... they are stored as circular memory buffers. So they won't persist after your phone reboots.Hertzog
@AlexLockwood that's not quite correct (anymore). have a look at https://mcmap.net/q/411249/-android-how-to-get-kernel-logs-after-kernel-panic /data/dontpanicAerology
My comment was based on information I read in this book: shop.oreilly.com/product/0636920021094.do If logs were constantly written to disk devices would perform very poorly. So I stand by my comment. Also this answer is definitely not true anymore since apps are no longer able to access logcat since API 16.Hertzog
H
0

I think that during one of major android update, crash logs are moved from /proc/last_kmsg to /sys/fs/pstore/console-ramoops-0

Hyperthyroidism answered 28/3, 2022 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.