一个物理设备上你如何保存一个Android应用程序日志文件? [英] How do you save an Android application log to a file on a physical device?

查看:360
本文介绍了一个物理设备上你如何保存一个Android应用程序日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么我的Andr​​oid应用程序的服务偶尔出现故障(无论是操作系统杀死它或crasch),因此我要救我的手机上的日志文件。怎么能是这样做?

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?

推荐答案

基本上你有两种可能性,通常第一个应该可以帮助你已经找到了坠毁的原因不会因为的logcat 编码什么应该显示发生错误,导致服务端。

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)使用的logcat命令

Log.i(您的标记,输出文本)您可以通过调用拦截使用Android Eclipse插件或者这些邮件亚行logcat 从你的命令行,让你的Andr​​oid设备连接和运行服务。

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.

参见 http://developer.android.com/guide/开发/工具/ adb.html#logat

2)写入标准输出

使用的System.out.println(...)命令,你可以配置你的设备写入标准输出到一个文件:

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

参见 http://developer.android.com/guide/开发/工具/ adb.html#标准输出

显然,你必须向S $ P $垫了很多的调试输出信息在你的应用程序,主要是在关键点。

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

祝你好运寻找错误!

这篇关于一个物理设备上你如何保存一个Android应用程序日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆