From 6559bdfbfd3bc5dfc20ac925e5039340593e8ebc Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Wed, 30 Oct 2024 21:33:33 +0100 Subject: [PATCH 1/2] log is now on stdout, except errors that are on stderr --- addons/io_scene_gltf2/io/com/debug.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/io_scene_gltf2/io/com/debug.py b/addons/io_scene_gltf2/io/com/debug.py index 697ce5457..7fae9cd89 100644 --- a/addons/io_scene_gltf2/io/com/debug.py +++ b/addons/io_scene_gltf2/io/com/debug.py @@ -19,6 +19,7 @@ import time import logging import logging.handlers +import sys # # Globals @@ -75,22 +76,30 @@ def profile_end(label=None): class Log: def __init__(self, loglevel): self.logger = logging.getLogger('glTFImporter') + self.error_logger = logging.getLogger('glTFImporter_errors') # For console display - self.console_handler = logging.StreamHandler() + self.console_handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter('%(asctime)s | %(levelname)s: %(message)s', "%H:%M:%S") self.console_handler.setFormatter(formatter) + # For console display - errors + self.error_console_handler = logging.StreamHandler(sys.stderr) + formatter_error = logging.Formatter('%(asctime)s | %(levelname)s: %(message)s', "%H:%M:%S") + self.error_console_handler.setFormatter(formatter_error) + # For popup display self.popup_handler = logging.handlers.MemoryHandler(1024 * 10) self.logger.addHandler(self.console_handler) + self.error_logger.addHandler(self.error_console_handler) # self.logger.addHandler(self.popup_handler) => Make sure to not attach the popup handler to the logger self.logger.setLevel(int(loglevel)) + self.error_logger.setLevel(logging.ERROR) def error(self, message, popup=False): - self.logger.error(message) + self.error_logger.error(message) if popup: self.popup_handler.buffer.append(('ERROR', message)) @@ -110,7 +119,7 @@ def debug(self, message, popup=False): self.popup_handler.buffer.append(('DEBUG', message)) def critical(self, message, popup=False): - self.logger.critical(message) + self.error_logger.critical(message) if popup: # There is no Critical level in Blender, so we use error self.popup_handler.buffer.append(('ERROR', message)) @@ -125,5 +134,6 @@ def messages(self): def flush(self): self.logger.removeHandler(self.console_handler) + self.error_logger.removeHandler(self.error_console_handler) self.popup_handler.flush() self.logger.removeHandler(self.popup_handler) From c1ad9f0cf3c9a181fa19ceb2952cdfcca569c169 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Wed, 30 Oct 2024 22:17:11 +0100 Subject: [PATCH 2/2] get export loglevel from ops parameter If not set, get it from app debug value --- addons/io_scene_gltf2/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/io_scene_gltf2/__init__.py b/addons/io_scene_gltf2/__init__.py index 83efca6e5..1fd72108d 100644 --- a/addons/io_scene_gltf2/__init__.py +++ b/addons/io_scene_gltf2/__init__.py @@ -991,6 +991,12 @@ class ExportGLTF2_Base(ConvertGLTF2_Base): default=False ) + export_loglevel: IntProperty( + name='Log Level', + description="Log Level", + default=-1, + ) + # Custom scene property for saving settings scene_key = "glTF2ExportSettings" @@ -1076,7 +1082,11 @@ def execute(self, context): # All custom export settings are stored in this container. export_settings = {} - export_settings['loglevel'] = set_debug_log() + # Get log level from parameters + # If not set, get it from Blender app debug value + export_settings['gltf_loglevel'] = self.export_loglevel + if export_settings['gltf_loglevel'] < 0: + export_settings['loglevel'] = set_debug_log() export_settings['exported_images'] = {} export_settings['exported_texture_nodes'] = []