Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
567 views
in Technique[技术] by (71.8m points)

logging - How do you save an Android application log to a file on a physical device?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...