From ead8a038930d71aca76a5d6950cc781759ac5288 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 13 Aug 2025 15:19:39 -0400 Subject: [PATCH] #19816: Capture additional logging under ScriptJob --- netbox/extras/jobs.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/netbox/extras/jobs.py b/netbox/extras/jobs.py index c4a1b3b26..8a039c7c8 100644 --- a/netbox/extras/jobs.py +++ b/netbox/extras/jobs.py @@ -59,6 +59,7 @@ class ScriptJob(JobRunner): else: script.log_failure(msg) logger.error(f"Script aborted with error: {e}") + self.logger.error(f"Script aborted with error: {e}") else: stacktrace = traceback.format_exc() @@ -66,9 +67,11 @@ class ScriptJob(JobRunner): message=_("An exception occurred: ") + f"`{type(e).__name__}: {e}`\n```\n{stacktrace}\n```" ) logger.error(f"Exception raised during script execution: {e}") + self.logger.error(f"Exception raised during script execution: {e}") if type(e) is not AbortTransaction: script.log_info(message=_("Database changes have been reverted due to error.")) + self.logger.info("Database changes have been reverted due to error.") # Clear all pending events. Job termination (including setting the status) is handled by the job framework. if request: @@ -108,9 +111,11 @@ class ScriptJob(JobRunner): # Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process # change logging, event rules, etc. if commit: + self.logger.info("Executing script (commit enabled)") with ExitStack() as stack: for request_processor in registry['request_processors']: stack.enter_context(request_processor(request)) self.run_script(script, request, data, commit) else: + self.logger.warning("Executing script (commit disabled)") self.run_script(script, request, data, commit)