如何捕获 kivy-client 崩溃日志并将其发送到我的服务器?

How can I catch kivy-client crash log and send it to my server?(如何捕获 kivy-client 崩溃日志并将其发送到我的服务器?)

本文介绍了如何捕获 kivy-client 崩溃日志并将其发送到我的服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当出现一些硬件问题并且我的 kivy 应用程序崩溃时,我遇到了问题.例如在 Android 或 iOS 上.普通用户看不到日志,我也看不到.

I have problems when some hardware issues appears and my kivy app crashes. For example on Android or iOS. Regular users can't see the log, neither can I.

所以,当我的应用程序启动时,我想创建单独的进程并以某种方式查看主应用程序的状态.万一它崩溃了,我想将错误日志发送到我的服务器.那么,最好的方法是什么?也许另一个过程是多余的,我可以用更简单的方式制作它?以及如何准确地捕获崩溃日志?...谢谢!

So, when my application starts, I want to create separate process and somehow look at the status of main application. In case of it's crash I'd like to send error log to my server. So, what is the best way to do this? Maybe another process is redundant and I can make it in more simple way? And how exactly I can catch crash log?...Thanks!

推荐答案

TLDR:使用 Sentry

有不同类型的崩溃和不同类型的工具.

There is different kind of crash, and different kind-of tools.

本机崩溃:通常是段错误,是您无法真正做任何事情的低级别崩溃.这就是您在 Play 商店标签上看到的内容,原生崩溃/艺术.任何回溯都不会与您交谈,因为您将看到 Python 解释器和所有其他线程的 C 跟踪.用户可以看到应用程序 XXX 突然退出"或类似的内容.有一些工具可以在本机崩溃的情况下显示更好的消息并将其发送到其他地方,但您的应用程序将永远无法恢复.使用此类工具您唯一能做的就是重新启动它.

Native crash: usually a segfault, a low level crash that you cannot really do anything. That's what you see on your Play store tab, native crash/art. None of the traceback will talk to you, as you'll see the C trace of your Python interpreter and all the others threads. The user can see a "The application XXX suddenly exited" or something like that. There is tools available to display nicer message in case of a native crash and send it somewhere else, but your application will never recover. The only thing you can do with such tools is to restart it.

Python 崩溃:好消息,您可以捕获它们并进行可理解的回溯.我建议您查看 Sentry.它是开源的,您可以在您的服务器上安装哨兵,当您的应用程序发生错误时,您可以将完整的回溯发送到您的哨兵安装.很有用.

Python crash: good news, you can catch them and have comprehensible traceback. I suggest you to look into Sentry. It's opensource, you can install sentry on your server, and when something bad happen in your app, you can send the full traceback to your sentry installation. Very useful.

集成到 Kivy 也很简单:

The integration into Kivy is also very simple:

if __name__ == "__main__":
    import traceback
    from raven import Client
    client = Client('requests+http://XXKEYXX@sentry.yourserver.com/sentry/1')
    try:
        YourApp().run()
    except:
        traceback.print_exc()
        ident = client.get_ident(client.captureException())
        print "Exception caught; reference is %s" % ident

不要忘记在 Android 中拥有 INTERNET 权限.如果没有互联网,它会在控制台上失败两次.但仅此而已.

Don't forget to have the INTERNET permission in Android. If there is no internet, it will fail twice on the console. But that's all.

此外,您可能希望将其插入 Kivy 的 ExceptionManager.如果异常发生在主循环中,那么您有可能捕获它而不退出应用程序(忽略异常).当心你是否正在做一些重要的事情:D

Also, you might want to plug that into the Kivy's ExceptionManager. If the exception happen in the main loop, then you have the possibility to catch it and not quit the app (ignore the exception). Beware if you were doing something important :D

这篇关于如何捕获 kivy-client 崩溃日志并将其发送到我的服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何捕获 kivy-client 崩溃日志并将其发送到我的服务器?

基础教程推荐