Commit c3107a53 authored by Gaetano Scandariato's avatar Gaetano Scandariato
Browse files

feat(logging): redirect python warnings to centralized logger

Intercepts all system warnings (including those from dependencies like PIL/Pillow)
and routes them through the PyAETNA centralized logger with a WARNING level.
This ensures that library-level warnings are captured in the run log files
rather than only appearing in stdout.
parent 06394fa9
Loading
Loading
Loading
Loading
Loading
+7 −0
Changes for PyAETNA/run.py: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import os
import yaml
import time as ttt
import time
import warnings
from typing import Optional

import jax
@@ -61,6 +62,12 @@ def run(configFile: str) -> None:
    from . import logger as _logger_module
    _logger_module._EIV_TRIGGERED = False

    # Redirect all warnings to the PyAETNA centralized logger
    def warn_with_log(message, category, filename, lineno, line=None, func=None):
        _log(f"Warning: {message}", level="WARNING")

    warnings.showwarning = warn_with_log

    # Resolve config path relative to the current working directory (cwd)
    # This ensures callers can pass paths relative to where they launch Python
    # or after changing directories in their application.