Android 手机重启后可以获取 logcat 日志吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3469016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I get logcat logs after phone reboots?
提问by Scott Saunders
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.
我正在测试具有长期运行服务的 android 应用程序。我正在使用 Eclipse,并将 USB 线与坐在我旁边的电话相连。由于它是一个长期持续的服务,我在它运行时做一些其他工作,并每隔一段时间检查一次 logcat 日志以确保一切都按预期进行。
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.
几分钟前,我注意到手机重新启动。我认为之前已经这样做了,因为它可以解释一些奇怪的应用程序行为。我迅速切换到 Eclipse 以查看发生了什么,并发现 logcat 日志(似乎)在重新启动期间被清除了。所以没有记录我的应用程序是否崩溃(并关闭了手机?!)或者是否有其他问题导致手机和我的应用程序关闭。
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.
无论如何我能找出发生了什么吗?这是一款开发手机,所以我不知道它是否经常自行重启/崩溃,还是仅在我的应用程序运行时。这是运行固件版本 2.1-update1 的摩托罗拉 Droid。
Thanks for your help.
谢谢你的帮助。
采纳答案by eldarerathis
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.
我不知道有什么方法可以做到这一点。但是,你可以在启动的logcatadb
用adb logcat -v time > logcat.txt
,然后再次运行你的应用程序。如果它第二次崩溃,那么你可以logcat.txt
在你的机器上查看输出。
回答by adamk
You can use adb bugreport
, which should contain some information regarding a spurious reboot - for example, a kernel panic, last logcat entries etc.
您可以使用adb bugreport
,它应该包含一些关于虚假重启的信息——例如,内核恐慌、最后的 logcat 条目等。
Be warned, though: this tool outputs immense amounts of information, so you'll have to dig deep to find what you need.
但是请注意:此工具会输出大量信息,因此您必须深入挖掘才能找到所需的信息。
回答by Aaron C
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.
我也遇到过这个问题。应该可以编写一个应用程序,将 logcat 输出连续保存到 SD 卡上的文件中。市场上有显示 logcat 输出的应用程序,所以我知道它可以从应用程序中访问。
@djv, I wasn't able to find a /log directory in either root or /data on my phone.
@djv,我无法在手机上的 root 或 /data 中找到 /log 目录。