問題描述
當出現一些硬件問題并且我的 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 崩潰日志并將其發送到我的服務器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!