From 9cb2f18384635c312d40737c8cfb595aff772251 Mon Sep 17 00:00:00 2001 From: Parth Shandilya <24358501+ParthS007@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:10:08 +0100 Subject: [PATCH] addons: log addon events --- weblate/addons/models.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/weblate/addons/models.py b/weblate/addons/models.py index a20b34957720..fffe314b42f5 100644 --- a/weblate/addons/models.py +++ b/weblate/addons/models.py @@ -203,6 +203,15 @@ def handle_addon_event( ): # Scope is used for logging scope = translation or component + # Log logging result and error flag for addon activity log + log_result = None + error_occurred = False + # Events to exclude from logging + exclude_from_logging = [ + "EVENT_UNIT_PRE_CREATE", + "EVENT_UNIT_POST_SAVE", + "EVENT_STORE_POST_LOAD", + ] # Shortcuts for frequently used variables if component is None and translation is not None: @@ -227,21 +236,16 @@ def handle_addon_event( op=f"addon.{event.name}", description=addon.name ): if isinstance(method, str): - getattr(addon.addon, method)(*args) + log_result = getattr(addon.addon, method)(*args) else: # Callback is used in tasks - method(addon) - AddonActivityLog.objects.create( - addon=addon, - component=component, - event=event.label, - # TODO: What to add here? - details={}, - ) + log_result = method(addon) except DjangoDatabaseError: raise except Exception as error: # Log failure + error_occurred = True + log_result = error scope.log_error( "failed %s add-on: %s: %s", event.label, addon.name, error ) @@ -256,8 +260,16 @@ def handle_addon_event( addon.name, ) addon.disable() - else: - scope.log_debug("completed %s add-on: %s", event.label, addon.name) + finally: + if event.label not in exclude_from_logging: + AddonActivityLog.objects.create( + addon=addon, + component=component, + event=event, + details={"result": log_result, "error": error_occurred}, + ) + else: + scope.log_debug("completed %s add-on: %s", event.label, addon.name) @receiver(vcs_pre_push)