From 7e8a379ad5d6153250716b0026c971e05b78f217 Mon Sep 17 00:00:00 2001 From: haiyimei Date: Thu, 5 Dec 2024 14:12:56 +0800 Subject: [PATCH] refactor: Change logging level from debug to trace in rendering job updates; enhance LoggerWrapper to support configurable log path level --- xrfeitoria/renderer/renderer_blender.py | 4 ++-- xrfeitoria/utils/tools.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/xrfeitoria/renderer/renderer_blender.py b/xrfeitoria/renderer/renderer_blender.py index fdf570c5..4a13dbc2 100644 --- a/xrfeitoria/renderer/renderer_blender.py +++ b/xrfeitoria/renderer/renderer_blender.py @@ -94,7 +94,7 @@ def receive_stdout( break text = f'[bold green]:rocket: Rendering Job{job_info}: frame {frame_count}/{frame_length}[/bold green]' spinner.update(text=text) - logger.debug(f'(XF-Rendering) Job{job_info}: frame {frame_count}/{frame_length}') + logger.trace(f'(XF-Rendering) Job{job_info}: frame {frame_count}/{frame_length}') # reset first_trigger = second_trigger = False else: @@ -116,7 +116,7 @@ def receive_stdout( break text = f'[bold green]:rocket: Rendering Job{job_info}: frame {frame_count}/{frame_length}[/bold green]' spinner.update(text=text) - logger.debug(f'(XF-Rendering) Job{job_info}: frame {frame_count}/{frame_length}') + logger.trace(f'(XF-Rendering) Job{job_info}: frame {frame_count}/{frame_length}') # reset first_trigger = second_trigger = False diff --git a/xrfeitoria/utils/tools.py b/xrfeitoria/utils/tools.py index e04ba2b4..c5727af2 100644 --- a/xrfeitoria/utils/tools.py +++ b/xrfeitoria/utils/tools.py @@ -73,6 +73,7 @@ def setup_logging( cls, level: Literal['RPC', 'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'] = 'INFO', log_path: 'Optional[PathLike]' = None, + log_path_level: Literal['RPC', 'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'] = 'DEBUG', replace: bool = True, ) -> 'loguru.Logger': """Setup logging to file and console. @@ -81,6 +82,8 @@ def setup_logging( level (Literal['RPC', 'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'], optional): logging level. Defaults to "INFO", find more in https://loguru.readthedocs.io/en/stable/api/logger.html. log_path (Path, optional): path to save the log file. Defaults to None. + log_path_level (Literal['RPC', 'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'], optional): + logging level for the log file. Defaults to 'DEBUG'. replace (bool, optional): replace the log file if exists. Defaults to True. """ if cls.is_setup: @@ -106,8 +109,9 @@ def setup_logging( log_path.parent.mkdir(parents=True, exist_ok=True) if replace and log_path.exists(): log_path.unlink(missing_ok=True) - _level = 'RPC' if level == 'RPC' else 'TRACE' - logger.add(log_path, level=_level, filter=cls.filter_unique, format=cls.logger_format, encoding='utf-8') + logger.add( + log_path, level=log_path_level, filter=cls.filter_unique, format=cls.logger_format, encoding='utf-8' + ) logger.info(f'Python Logging to "{log_path.as_posix()}"') cls.is_setup = True return logger @@ -148,6 +152,7 @@ def setup_encoding( def setup_logger( level: Literal['RPC', 'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'] = 'INFO', log_path: 'Optional[PathLike]' = None, + log_path_level: Literal['RPC', 'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'] = 'DEBUG', replace: bool = True, ) -> 'loguru.Logger': """Setup logging to file and console. @@ -163,10 +168,12 @@ def setup_logger( - 'INFO': logging info messages. - ... log_path (Path, optional): path to save the log file. Defaults to None. + log_path_level (Literal['RPC', 'TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'], optional): + logging level for the log file. Defaults to 'DEBUG'. replace (bool, optional): replace the log file if exists. Defaults to True. """ try: - return LoggerWrapper.setup_logging(level, log_path, replace) + return LoggerWrapper.setup_logging(level, log_path, log_path_level, replace) except Exception as e: import traceback