From ead610151f57b10af828e0a20b0b19fe9bc3a503 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 11 Jun 2022 23:07:09 +0200 Subject: [PATCH] Notification log - also log normal requests and make the log easier to find --- changedetectionio/__init__.py | 17 ++++++++++++----- changedetectionio/notification.py | 2 ++ .../templates/_common_fields.jinja | 3 ++- .../templates/notification-log.html | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index cbc4854e..123d16dd 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -924,7 +924,7 @@ def changedetection_app(config=None, datastore_o=None): def notification_logs(): global notification_debug_log output = render_template("notification-log.html", - logs=notification_debug_log if len(notification_debug_log) else ["No errors or warnings detected"]) + logs=notification_debug_log if len(notification_debug_log) else ["Notification logs are empty - no notifications sent yet."]) return output @@ -1244,6 +1244,9 @@ def check_for_new_version(): def notification_runner(): global notification_debug_log + from datetime import datetime + import json + while not app.config.exit.is_set(): try: # At the moment only one thread runs (single runner) @@ -1252,9 +1255,12 @@ def notification_runner(): time.sleep(1) else: - # Process notifications + + now = datetime.now() + try: from changedetectionio import notification + notification.process_notification(n_object, datastore) except Exception as e: @@ -1268,9 +1274,10 @@ def notification_runner(): log_lines = str(e).splitlines() notification_debug_log += log_lines - # Trim the log length - notification_debug_log = notification_debug_log[-100:] - + # Process notifications + notification_debug_log+= ["{} - SENDING {}".format(now.strftime("%Y/%m/%d %H:%M:%S,000"), json.dumps(n_object))] + # Trim the log length + notification_debug_log = notification_debug_log[-100:] # Thread runner to check every minute, look for new watches to feed into the Queue. def ticker_thread_check_time_launch_checks(): diff --git a/changedetectionio/notification.py b/changedetectionio/notification.py index b3d07d9a..4ee520b0 100644 --- a/changedetectionio/notification.py +++ b/changedetectionio/notification.py @@ -97,6 +97,8 @@ def process_notification(n_object, datastore): if log_value and 'WARNING' in log_value or 'ERROR' in log_value: raise Exception(log_value) + + # Notification title + body content parameters get created here. def create_notification_parameters(n_object, datastore): from copy import deepcopy diff --git a/changedetectionio/templates/_common_fields.jinja b/changedetectionio/templates/_common_fields.jinja index 961ff1db..418abc16 100644 --- a/changedetectionio/templates/_common_fields.jinja +++ b/changedetectionio/templates/_common_fields.jinja @@ -14,7 +14,7 @@
  • Use AppRise URLs for notification to just about any service! Please read the notification services wiki here for important configuration notes.
  • discord:// only supports a maximum 2,000 characters of notification text, including the title.
  • tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user.
  • -
  • Go here for notification debug logs
  • +
    @@ -22,6 +22,7 @@ {% if emailprefix %} Add email {% endif %} + Notification debug logs
    diff --git a/changedetectionio/templates/notification-log.html b/changedetectionio/templates/notification-log.html index 6fd92a1b..ee76e259 100644 --- a/changedetectionio/templates/notification-log.html +++ b/changedetectionio/templates/notification-log.html @@ -4,7 +4,7 @@
    -

    The following issues were detected when sending notifications

    +

    Notification debug log

      {% for log in logs|reverse %}