From e9f316d5d99cd9558a2b56179faec6d7f768956d Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Wed, 20 Sep 2023 14:45:04 +0200 Subject: [PATCH] Add logging and cleanup for backend plugins This commit adds improved logging for backend plugins in Cura. Now, each time a plugin is started, an info log is generated with the used command. All plugin output will also be logged to a separate file for easier debugging. Additionally, a cleanup operation has been added to remove existing plugin logs before generating a new one, to prevent the file size from getting too large. Contributes to CURA-11064 --- cura/BackendPlugin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cura/BackendPlugin.py b/cura/BackendPlugin.py index 7f18af0360..6392b1c50f 100644 --- a/cura/BackendPlugin.py +++ b/cura/BackendPlugin.py @@ -73,12 +73,17 @@ class BackendPlugin(AdditionalSettingDefinitionsAppender, PluginObject): """ if not self.usePlugin(): return False + Logger.info(f"Starting backend_plugin [{self._plugin_id}] with command: {self._validatePluginCommand()}") + plugin_log_path = os.path.join(Resources.getDataStoragePath(), f"{self.getPluginId()}.log") + if os.path.exists(plugin_log_path): + try: + os.remove(plugin_log_path) + except: + pass # removing is only done such that it doesn't grow out of proportions, if it fails once or twice that is okay + Logger.info(f"Logging plugin output to: {plugin_log_path}") try: # STDIN needs to be None because we provide no input, but communicate via a local socket instead. # The NUL device sometimes doesn't exist on some computers. - Logger.info(f"Starting backend_plugin [{self._plugin_id}] with command: {self._validatePluginCommand()}") - plugin_log_path = os.path.join(Resources.getDataStoragePath(), f"{self.getPluginId()}.log") - Logger.info(f"Logging plugin output to: {plugin_log_path}") with open(plugin_log_path, 'a') as f: popen_kwargs = { "stdin": None,