Browse Source

Do not notify warning/errors from same source twice

Closes #1842
pull/1849/head
Safihre 4 years ago
parent
commit
89c8b6a0a5
  1. 23
      SABnzbd.py

23
SABnzbd.py

@ -136,16 +136,29 @@ class GUIHandler(logging.Handler):
except TypeError: except TypeError:
parsed_msg = record.msg + str(record.args) parsed_msg = record.msg + str(record.args)
if record.levelno == logging.WARNING: warning = {
sabnzbd.notifier.send_notification(T("Warning"), parsed_msg, "warning") "type": record.levelname,
else: "text": parsed_msg,
sabnzbd.notifier.send_notification(T("Error"), parsed_msg, "error") "time": int(time.time()),
"origin": "%s%d" % (record.filename, record.lineno),
}
# Append traceback, if available # Append traceback, if available
warning = {"type": record.levelname, "text": parsed_msg, "time": int(time.time())}
if record.exc_info: if record.exc_info:
warning["text"] = "%s\n%s" % (warning["text"], traceback.format_exc()) 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 # Loose the oldest record
if len(self.store) >= self._size: if len(self.store) >= self._size:
self.store.pop(0) self.store.pop(0)

Loading…
Cancel
Save