small changes

This commit is contained in:
Siddhesh Agarwal
2024-11-01 15:27:15 +05:30
parent d62f297b68
commit ad1800840d
2 changed files with 9 additions and 3 deletions
+1 -2
View File
@@ -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()
+8 -1
View File
@@ -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