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

查看:110
本文介绍了如何捕获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:使用哨兵

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

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崩溃:好消息,您可以捕获它们并进行全面的追溯.建议您查看哨兵.它是开源的,您可以在服务器上安装哨兵,当应用程序发生问题时,您可以将完整的追溯发送到哨兵安装.非常有用.

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崩溃日志并将其发送到我的服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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