Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime van Kessel <nallath@gmail.com>2019-11-22 15:26:17 +0300
committerJaime van Kessel <nallath@gmail.com>2019-11-22 15:26:17 +0300
commit6c8fddc765d9d9b90f477a650427c6f60e8eb140 (patch)
treeb8173f94f6038f254a1d10528bb2aa52d6da8b33 /plugins/SentryLogger
parent23057f786fefc63dd77d67b47c7e4ece8c5dda4f (diff)
Add sentry logger to display breadcrumbs
Diffstat (limited to 'plugins/SentryLogger')
-rw-r--r--plugins/SentryLogger/SentryLogger.py43
-rw-r--r--plugins/SentryLogger/__init__.py12
-rw-r--r--plugins/SentryLogger/plugin.json8
3 files changed, 63 insertions, 0 deletions
diff --git a/plugins/SentryLogger/SentryLogger.py b/plugins/SentryLogger/SentryLogger.py
new file mode 100644
index 0000000000..0c0730b1dc
--- /dev/null
+++ b/plugins/SentryLogger/SentryLogger.py
@@ -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 \ No newline at end of file
diff --git a/plugins/SentryLogger/__init__.py b/plugins/SentryLogger/__init__.py
new file mode 100644
index 0000000000..6cf92ab624
--- /dev/null
+++ b/plugins/SentryLogger/__init__.py
@@ -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() }
diff --git a/plugins/SentryLogger/plugin.json b/plugins/SentryLogger/plugin.json
new file mode 100644
index 0000000000..fef4e1c554
--- /dev/null
+++ b/plugins/SentryLogger/plugin.json
@@ -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"
+}