Skip to content

Commit

Permalink
Improve logging for exceptions (e.g. TimeoutError)
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusP committed May 17, 2024
1 parent a04cc18 commit 8e39080
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ async def base_exception_handler(
status_code: int = 400,
include_detail: bool = False,
) -> JSONResponse:
logger.exception(exc)
if include_detail and request.app.state.settings.debug:
reason = f"<{exc.__class__.__name__}>: {str(exc)}"
elif include_detail:
Expand Down Expand Up @@ -521,7 +522,7 @@ async def default_handler(request: Request, exc: Exception) -> JSONResponse:
)


def configure_logging(loglevel: str = "INFO"):
def configure_logging(loglevel: str = "INFO", backtrace: bool = False):
logger.remove()
intercept_logging()
logger.add(
Expand All @@ -532,6 +533,8 @@ def configure_logging(loglevel: str = "INFO"):
"<fg #FF9900>{time:%Y-%m-%d:%H:%m:%S}</fg #FF9900> "
"<level>{level:9} {message}</level>"
),
backtrace=backtrace,
diagnose=backtrace,
)


Expand All @@ -541,7 +544,7 @@ def app_factory() -> FastAPI:
if settings.is_test:
settings = PhoenixdLNURLSettings(_env_file="test.env") # type: ignore

configure_logging(settings.log_level)
configure_logging(settings.log_level, settings.debug)
logger.debug("Loaded settings: {settings}", settings=settings)

if not settings.debug:
Expand Down

0 comments on commit 8e39080

Please sign in to comment.