22

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.

Scott Saunders
  • 27,788
  • 14
  • 52
  • 63
  • http://stackoverflow.com/questions/3361230/android-retrieve-logcat-before-crash-reboot-on-a-real-device 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. – Mike Aug 12 '10 at 15:08
  • 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.) – Michael Apr 28 '14 at 21:26
  • Possible duplicate of [Android: How to get kernel logs after kernel panic?](https://stackoverflow.com/questions/9682306/android-how-to-get-kernel-logs-after-kernel-panic) – childno͡.de Jun 14 '17 at 16:25

3 Answers3

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.

eldarerathis
  • 32,541
  • 9
  • 86
  • 93
  • 2
    Note that file writes are buffered, so the very last words before rebooting may not be flushed to the file. – adamk Aug 12 '10 at 17:01
  • @adamk: Also a good point. Is there a cleaner way to do this (I'm guessing `adb bugreport`)? – eldarerathis Aug 12 '10 at 17:03
  • 1
    @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. – adamk Aug 12 '10 at 17:11
  • 1
    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. – Scott Saunders Aug 12 '10 at 17:12
  • @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. – eldarerathis Aug 12 '10 at 17:21
  • `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. – OneWorld Dec 21 '10 at 14:05
  • @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. – eldarerathis Dec 21 '10 at 16:41
  • 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. – Trevor May 10 '14 at 19:19
12

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.

adamk
  • 38,100
  • 6
  • 47
  • 56
  • 2
    Wow. That gave me 20,000+ lines. I'm sure it's great information, though I don't know what to do with it! – Scott Saunders Aug 12 '10 at 17:11
  • 1
    @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. – adamk Aug 12 '10 at 17:13
  • 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. – Scott Saunders Aug 12 '10 at 17:18
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.

Aaron C
  • 3,240
  • 1
  • 21
  • 22
  • 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. – Alex Lockwood Dec 20 '13 at 06:02
  • @AlexLockwood that's not quite correct (anymore). have a look at https://stackoverflow.com/a/10525021/529977 `/data/dontpanic` – childno͡.de Jun 14 '17 at 16:24
  • My comment was based on information I read in this book: http://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. – Alex Lockwood Jun 14 '17 at 18:06