fix notify on error

This commit is contained in:
avollkopf 2022-12-02 20:25:27 +01:00
parent 9f655c9393
commit cde20f647d
2 changed files with 16 additions and 15 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.0.7.rc2"
__version__ = "4.0.7.rc3"
__codename__ = "November Rain"

View file

@ -12,24 +12,25 @@ class NotificationController:
'''
self.cbpi = cbpi
self.logger = logging.getLogger(__name__)
NOTIFY_ON_ERROR = self.cbpi.config.get("NOTIFY_ON_ERROR", "No")
if NOTIFY_ON_ERROR == "Yes":
logging.root.addFilter(self.notify_log_event)
logging.root.addFilter(self.notify_log_event)
self.callback_cache = {}
self.listener = {}
def notify_log_event(self, record):
try:
if record.levelno > 20:
# on log events higher then INFO we want to notify all clients
type = NotificationType.WARNING
if record.levelno > 30:
type = NotificationType.ERROR
self.cbpi.notify(title=f"{record.levelname}", message=record.msg, type = type)
except Exception as e:
pass
finally:
return True
NOTIFY_ON_ERROR = self.cbpi.config.get("NOTIFY_ON_ERROR", "No")
if NOTIFY_ON_ERROR == "Yes":
try:
if record.levelno > 20:
# on log events higher then INFO we want to notify all clients
type = NotificationType.WARNING
if record.levelno > 30:
type = NotificationType.ERROR
self.cbpi.notify(title=f"{record.levelname}", message=record.msg, type = type)
except Exception as e:
pass
finally:
return True
return True
def add_listener(self, method):
listener_id = shortuuid.uuid()