将应用程序的 Logcat 输出发送到电子邮件地址
我们现在正在与几个朋友一起测试我们的应用程序。有时,有些错误不会引发异常。所以我真的不知道问题是什么。所以我认为实现一个菜单项是一个好主意,该菜单项允许将 logcat 输出发送到电子邮件地址,以便我们可以检查日志。
不幸的是,我没有在互联网上找到如何从手机中提取 logcat 的提示。如何发送电子邮件应该不是问题。
We are now testing our application with a few friends. Sometimes there are some errors which don't throw an exception. So I don't really know whats the problem was. So I thought it would be a good idea to implement a menu item which allows to send the logcat output to a e-mail address, so that we can examine the log.
Unfortunately I didn't find a hint in the Internet how to extract the logcat from a phone. How to send an email shouldn't be the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
查看 android-log-collector,它的作用 从 Android 4.1 开始,无法收集任意 LogCat 数据。从来没有记录和支持的方法来做到这一点,并且未记录/不支持的方法 被 Jelly Bean 锁定。对于您自己的崩溃,最好使用崩溃日志库,例如 ACRA。
Look at android-log-collector, as it does what you are trying to do.It is not possible to collect arbitrary LogCat data as of Android 4.1. There was never a documented and supported way of doing that, and the undocumented/unsupported way was locked down in Jelly Bean. For your own crashes, you are better served using a crash logging library, like ACRA.
我还会研究 Flurry (flurry.com),它不仅为您提供一般分析,还允许您记录任意信息,并且还可以为您记录未捕获的异常。我只用了 5 分钟就完成了设置,但要记住的一件事是,它不像电子邮件提醒那样实时。您必须等待几个小时才能在应用程序中登录的内容显示在他们的仪表板上。如果您有一个非常轻量级的应用程序,它也可能有点过大,但我注意到使用该服务后我的应用程序没有性能损失。
I would also look into Flurry (flurry.com) which not only gives you general analytics but allows you to log arbitrary info and also logs uncaught exceptions for you. I set it up in literally 5 minutes, but one thing to keep in mind is that it's not real-time like an email alert. You'll have to wait a few hours for what you log in your app to show up on their dashboard. It could also be overkill if you have a really lightweight app, but I've noticed no performance loss in my app as a result of using the service.
我发现 LogCollector 确实非常有用(CommonsWare 的提示)
:不要忘记在您自己的应用程序中设置:
I found the LogCollector very usefull indeed (the tip from CommonsWare):
And don't forget to set in your own application:
我绝对建议您在此处查看此项目
I'd definitely recommend to look also at this project here
此解决方案不发送电子邮件,而是通过 UDP 将其发送到服务器。
https://github.com/Chemik/logcatudp
源代码已提供。它可以轻松嵌入到我们自己的应用程序中。我还没有尝试这样做。
This solution doesn't send an email, but sends it to a server through UDP.
https://github.com/Chemik/logcatudp
The source code is available. It can be easily embedded in our own app. I haven't tried to do so.
在您的清单文件中,授予以下权限:
在您的第一个/启动器活动中,在写入以下行之后
:这会将您的应用程序的 logcat 写入设备的外部存储
用于将 logcat 发送到所需的电子邮件地址:使用以下方法
检查是否存在的方法是否授予写入外部存储的权限:
/* 检查外部存储是否可用于读写 */
In your manifest file give the following permissions:
In your first/launcher activity, right after the
Write below lines: This will write your App's logcat to your device's external storage
For sending the logcat to desired email address: use below method
Method for checking whether the permissions for Writing to External storage is given or not:
/* Checks if external storage is available for read and write */
谢谢你 2,但通过浏览 android-log-collector 论坛,我找到了一个 解决方案,它甚至更容易句柄:
您可以在服务器上的某个位置存储 php 文件(或者如果您不想使用自己的服务器,他们的服务器上也有一个脚本)。在此 php 文件中,您可以定义当发布消息到达服务器时应执行的操作。我刚刚定义了一个非常简单的代码,它将数据转发到我的邮件地址。
仅当抛出未捕获的异常时,此方法才有效。但是可以扩展默认的未捕获异常处理程序,这样不仅可以获取堆栈跟踪,还可以获取 logcat。
Thanks to you 2 but by browsing the android-log-collector forum I found a solution that is even easier to handle:
There you can store a php file somewhere on your server (or if you dont want to use your own server, they also have a script on their server). In this php file you can define what shall be done when the post message reaches the server. I just definded a very simple code which forwards the data to my mail adress.
This only works if an uncaught exception was thrown. But one could extend the default uncaught exception handler, so that it's also possible to not only get the stacktrace but also the logcat.