Skip to content

Commit

Permalink
refactor: Change logging level from debug to trace in rendering job u…
Browse files Browse the repository at this point in the history
…pdates; enhance LoggerWrapper to support configurable log path level
  • Loading branch information
HaiyiMei committed Dec 5, 2024
1 parent 5fac24b commit 7e8a379
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions xrfeitoria/renderer/renderer_blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
13 changes: 10 additions & 3 deletions xrfeitoria/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit 7e8a379

Please sign in to comment.