5

I want to know why my Android application service occasionally goes down (whether it's the OS killing it or a crasch) and therefore I want to save a log file on my phone. How can is this be done?

Christian
  • 7,433
  • 4
  • 36
  • 61

1 Answers1

3

Basically you got two possibilities and normally the first one should help you finding already the reason for the crash without coding anything since the logcat should show up the error occurred that led to the service end.

1) Using the logcat command

Having Log.i("your tag", "output text") you can intercept those messages using the Android Eclipse plugin or by calling adb logcat from your command line, having your Android device connected and your service running.

See also http://developer.android.com/guide/developing/tools/adb.html#logat

2) Writing to stdout

Using the System.out.println("...") command you can configure your device to write the stdout into a file:

adb shell stop
adb shell setprop log.redirect-stdio true
adb shell start

See also http://developer.android.com/guide/developing/tools/adb.html#stdout

Obviously you have to spread a lot of debug output messages over your application, mainly at the critical points.

Good luck for finding the error!

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
  • 6
    Thanks! But doesn't both these options require that the device is connected to the computer running eclipse? I want to see the log produced after the device has been running in "production", i.e. while I'm carrying it around and using it normally. – Christian Feb 24 '11 at 13:50
  • 1
    Found a tool on the market called aLogCat which suits my needs. – Christian Feb 24 '11 at 20:23
  • The second options writes the log into a file on the device -- ``log.redirect-stdio`` – Lars Blumberg Feb 25 '11 at 02:46
  • Hi christain, am also trying to do the same, can you please help me by giving me some references. – Shalini Sep 16 '16 at 14:27
  • Christian can you give us a link or reference to the solution you found – Gray Feb 16 '21 at 23:35
  • https://play.google.com/store/search?q=alogcat&c=apps – Gray Feb 17 '21 at 00:23
  • @Gray sorry, this was 10 years ago so I don't really remember. Other than the comments above I'm afraid I can't help. – Christian Feb 17 '21 at 11:48