diff --git a/simplemind/logging.py b/simplemind/logging.py index 6dcf779..369c4c1 100644 --- a/simplemind/logging.py +++ b/simplemind/logging.py @@ -8,10 +8,9 @@ from .settings import settings def logger(func: Callable[..., Any]) -> Callable[..., Any]: """A @logger decorator that logs the function parameters, function returns, and exceptions raised if logging is enabled.""" - is_logging_enabled = settings.logging.enabled def wrapper(*args, **kwargs) -> Any: - if not is_logging_enabled: + if not settings.logging.enabled: return func(*args, **kwargs) logfire.info(f"Calling {func.__name__} with args: {args}, kwargs: {kwargs}") t1 = time.perf_counter() diff --git a/simplemind/settings.py b/simplemind/settings.py index 8d690af..a5548e7 100644 --- a/simplemind/settings.py +++ b/simplemind/settings.py @@ -16,16 +16,23 @@ class LoggingConfig(BaseSettings): # adding imports here to avoid forced dependencies try: import logfire + from logging import basicConfig except ImportError as e: raise ImportError( "To enable logging, please install logfire: `pip install logfire`" ) from e - from logging import basicConfig self.enabled = True logfire.configure(**kwargs) basicConfig(handlers=[logfire.LogfireLoggingHandler()]) + try: + logfire.configure(**kwargs) + basicConfig(handlers=[logfire.LogfireLoggingHandler()]) + except Exception as e: + self.enabled = False # Reset flag on failure + raise RuntimeError("Failed to configure logging") from e + def disable_logging(self) -> None: """Disable logging for the application.""" self.enabled = False