How can I catch kivy-client crash log and send it to my server?

ぃ、小莉子 提交于 2021-02-19 06:40:36

问题


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!


回答1:


TLDR: Use Sentry

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

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 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.

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

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.

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



来源:https://stackoverflow.com/questions/21063046/how-can-i-catch-kivy-client-crash-log-and-send-it-to-my-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!