☔ Add fqcn of callbacks to exception loggers

Will allow us to filter for them.
This commit is contained in:
Gina Häußge committed 2019-09-09 13:45:22 +02:00
1 parent 5079e7e891
commit a855f3e62c
6 files changed
+47 -10

No files matched your search

+3 -1
View File
@@ -17,6 +17,7 @@ from .destinations import FileDestinations
from .analysis import QueueEntry, AnalysisQueue
from .storage import LocalFileStorage
from .util import AbstractFileWrapper, StreamWrapper, DiskFileWrapper
from octoprint.util import get_fully_qualified_classname as fqcn
from collections import namedtuple
@@ -429,7 +430,8 @@ class FileManager(object):
self._last_slicing_progress = progress_int
for callback in self._slicing_progress_callbacks:
try: callback.sendSlicingProgress(slicer, source_location, source_path, dest_location, dest_path, progress_int)
except: self._logger.exception("Exception while pushing slicing progress")
except: self._logger.exception("Exception while pushing slicing progress",
extra=dict(callback=fqcn(callback)))
if progress_int:
def call_plugins(slicer, source_location, source_path, dest_location, dest_path, progress):
+6 -1
View File
@@ -19,6 +19,7 @@ import time
from octoprint.events import Events, eventManager
from octoprint.settings import settings
from octoprint.util import monotonic_time
from octoprint.util import get_fully_qualified_classname as fqcn
class QueueEntry(collections.namedtuple("QueueEntry", "name, path, type, location, absolute_path, printer_profile, analysis")):
@@ -109,7 +110,11 @@ class AnalysisQueue(object):
def _analysis_finished(self, entry, result):
for callback in self._callbacks:
callback(entry, result)
try:
callback(entry, result)
except:
self._logger.exception(u"Error while pushing analysis data to callback {}".format(callback),
extra=dict(callback=fqcn(callback)))
eventManager().fire(Events.METADATA_ANALYSIS_FINISHED, {"name": entry.name,
"path": entry.path,
"origin": entry.location,
+11 -5
View File
@@ -30,6 +30,7 @@ from octoprint.util import comm as comm
from octoprint.util import InvariantContainer
from octoprint.util import to_unicode
from octoprint.util import monotonic_time
from octoprint.util import get_fully_qualified_classname as fqcn
class Printer(PrinterInterface, comm.MachineComPrintCallback):
@@ -174,28 +175,32 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
try:
callback.on_printer_add_temperature(data)
except:
self._logger.exception(u"Exception while adding temperature data point to callback {}".format(callback))
self._logger.exception(u"Exception while adding temperature data point to callback {}".format(callback),
extra=dict(callback=fqcn(callback)))
def _sendAddLogCallbacks(self, data):
for callback in self._callbacks:
try:
callback.on_printer_add_log(data)
except:
self._logger.exception(u"Exception while adding communication log entry to callback {}".format(callback))
self._logger.exception(u"Exception while adding communication log entry to callback {}".format(callback),
extra=dict(callback=fqcn(callback)))
def _sendAddMessageCallbacks(self, data):
for callback in self._callbacks:
try:
callback.on_printer_add_message(data)
except:
self._logger.exception(u"Exception while adding printer message to callback {}".format(callback))
self._logger.exception(u"Exception while adding printer message to callback {}".format(callback),
extra=dict(callback=fqcn(callback)))
def _sendCurrentDataCallbacks(self, data):
for callback in self._callbacks:
try:
callback.on_printer_send_current_data(copy.deepcopy(data))
except:
self._logger.exception(u"Exception while pushing current data to callback {}".format(callback))
self._logger.exception(u"Exception while pushing current data to callback {}".format(callback),
extra=dict(callback=fqcn(callback)))
#~~ callback from metadata analysis event
@@ -1020,7 +1025,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
})
callback.on_printer_send_initial_data(data)
except:
self._logger.exception("Error while trying to send initial state update")
self._logger.exception(u"Error while pushing initial state update to callback {}".format(callback),
extra=dict(callback=fqcn(callback)))
def _getStateFlags(self):
return self._dict(operational=self.is_operational(),
+3 -1
View File
@@ -23,6 +23,7 @@ from octoprint.settings import settings
from octoprint.events import eventManager, Events
from octoprint.plugin import plugin_manager
from octoprint.util import monotonic_time
from octoprint.util import get_fully_qualified_classname as fqcn
import sarge
import collections
@@ -304,7 +305,8 @@ def notify_callbacks(timelapse):
config = timelapse.config_data()
for callback in _update_callbacks:
try: callback.sendTimelapseConfig(config)
except: logging.getLogger(__name__).exception("Exception while pushing timelapse configuration")
except: logging.getLogger(__name__).exception("Exception while pushing timelapse configuration",
extra=dict(callback=fqcn(callback)))
def configure_timelapse(config=None, persist=False):
+5 -2
View File
@@ -21,6 +21,7 @@ from builtins import range, bytes
from octoprint.settings import settings as s
from octoprint.util import atomic_write, to_bytes, deprecated, monotonic_time
from octoprint.util import get_fully_qualified_classname as fqcn
class UserManager(object):
valid_roles = ["user", "admin"]
@@ -90,7 +91,8 @@ class UserManager(object):
try:
callback("login", user)
except:
self._logger.exception("Error while calling login callback {!r}".format(callback))
self._logger.exception("Error while calling login callback {!r}".format(callback),
extra=dict(callback=fqcn(callback)))
return user
@@ -122,7 +124,8 @@ class UserManager(object):
try:
callback("logout", user)
except:
self._logger.exception("Error while calling logout callback {!r}".format(callback))
self._logger.exception("Error while calling logout callback {!r}".format(callback),
extra=dict(callback=fqcn(callback)))
def _cleanup_sessions(self):
for session, user in self._session_users_by_session.items():
+19
View File
@@ -228,6 +228,25 @@ def get_class(name):
raise ImportError("No module named " + name)
def get_fully_qualified_classname(o):
"""
Returns the fully qualified class name for an object.
Based on https://stackoverflow.com/a/2020083
Args:
o: the object of which to determine the fqcn
Returns:
(str) the fqcn of the object
"""
module = getattr(o.__class__, "__module__", None)
if module is None:
return o.__class__.__name__
return module + "." + o.__class__.__name__
def get_exception_string():
"""
Retrieves the exception info of the last raised exception and returns it as a string formatted as