diff --git a/SABnzbd.py b/SABnzbd.py index bd7f74e..bb8c1a7 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -136,16 +136,29 @@ class GUIHandler(logging.Handler): except TypeError: parsed_msg = record.msg + str(record.args) - if record.levelno == logging.WARNING: - sabnzbd.notifier.send_notification(T("Warning"), parsed_msg, "warning") - else: - sabnzbd.notifier.send_notification(T("Error"), parsed_msg, "error") + warning = { + "type": record.levelname, + "text": parsed_msg, + "time": int(time.time()), + "origin": "%s%d" % (record.filename, record.lineno), + } # Append traceback, if available - warning = {"type": record.levelname, "text": parsed_msg, "time": int(time.time())} if record.exc_info: warning["text"] = "%s\n%s" % (warning["text"], traceback.format_exc()) + # Do not notify the same notification within 1 minute from the same source + # This prevents endless looping if the notification service itself throws an error/warning + # We don't check based on message content, because if it includes a timestamp it's not unique + if not any( + stored_warning["origin"] == warning["origin"] and stored_warning["time"] + DEF_TIMEOUT > time.time() + for stored_warning in self.store + ): + if record.levelno == logging.WARNING: + sabnzbd.notifier.send_notification(T("Warning"), parsed_msg, "warning") + else: + sabnzbd.notifier.send_notification(T("Error"), parsed_msg, "error") + # Loose the oldest record if len(self.store) >= self._size: self.store.pop(0)