Add sentry logger to display breadcrumbs

This commit is contained in:
Jaime van Kessel 2019-11-22 13:26:17 +01:00
parent 23057f786f
commit 6c8fddc765
No known key found for this signature in database
GPG key ID: 3710727397403C91
4 changed files with 80 additions and 0 deletions

View file

@ -0,0 +1,43 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from UM.Logger import LogOutput
from typing import Set
from sentry_sdk import add_breadcrumb
from typing import Optional
class SentryLogger(LogOutput):
def __init__(self) -> None:
super().__init__()
self._show_once = set() # type: Set[str]
## Log the message to the sentry hub as a breadcrumb
# \param log_type "e" (error), "i"(info), "d"(debug), "w"(warning) or "c"(critical) (can postfix with "_once")
# \param message String containing message to be logged
def log(self, log_type: str, message: str) -> None:
level = self._translateLogType(log_type)
if level is None:
if message not in self._show_once:
level = self._translateLogType(log_type[0])
if level is not None:
self._show_once.add(message)
add_breadcrumb(level=level, message=message)
else:
add_breadcrumb(level=level, message=message)
@staticmethod
def _translateLogType(log_type: str) -> Optional[str]:
level = None
if log_type == "w":
level = "warning"
elif log_type == "i":
level = "info"
elif log_type == "c":
level = "fatal"
elif log_type == "e":
level = "error"
elif log_type == "d":
level = "debug"
return level

View file

@ -0,0 +1,12 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from . import SentryLogger
def getMetaData():
return {}
def register(app):
return { "logger": SentryLogger.SentryLogger() }

View file

@ -0,0 +1,8 @@
{
"name": "Sentry Logger",
"author": "Ultimaker B.V.",
"version": "1.0.0",
"description": "Logs certain events so that they can be used by the crash reporter",
"api": "7.0",
"i18n-catalog": "cura"
}

View file

@ -407,6 +407,23 @@
}
}
},
"SentryLogger": {
"package_info": {
"package_id": "SentryLogger",
"package_type": "plugin",
"display_name": "Sentry Logger",
"description": "Logs certain events so that they can be used by the crash reporter",
"package_version": "1.0.0",
"sdk_version": "7.0.0",
"website": "https://ultimaker.com",
"author": {
"author_id": "UltimakerPackages",
"display_name": "Ultimaker B.V.",
"email": "plugins@ultimaker.com",
"website": "https://ultimaker.com"
}
}
},
"SimulationView": {
"package_info": {
"package_id": "SimulationView",