mirror of
https://github.com/kennethreitz/simplemind.git
synced 2026-06-05 06:46:18 +00:00
small changes
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user