Skip to content

Unify backend logging, add context keys, and capture uncaught exceptions#425

Open
AJaySi wants to merge 1 commit intomainfrom
codex/enhance-logging-configuration-and-startup-flow
Open

Unify backend logging, add context keys, and capture uncaught exceptions#425
AJaySi wants to merge 1 commit intomainfrom
codex/enhance-logging-configuration-and-startup-flow

Conversation

@AJaySi
Copy link
Owner

@AJaySi AJaySi commented Mar 12, 2026

Motivation

  • Ensure all runtime errors (sync and async) are captured and logged with full tracebacks to improve observability and post-mortem debugging.
  • Provide a consistent, minimally-verbose default logging output while allowing verbose developer mode to show full diagnostics.
  • Route Uvicorn logs into the same sinks/format so startup/server logs match application logs and respect the chosen verbosity.

Description

  • Added global uncaught exception handling by registering sys.excepthook and an asyncio loop exception handler to surface unhandled exceptions with tracebacks via Loguru in backend/logging_config.py.
  • Introduced default structured context keys (request_id, job_id, user_id) via logger.configure(patcher=...) and included them in a shared common_format so logger.bind(...) context appears consistently.
  • Implemented an InterceptHandler that routes standard logging records into Loguru and wired uvicorn, uvicorn.error, and uvicorn.access to use this handler so they share the same sinks/format in both verbose and non-verbose modes.
  • Preserved concise non-verbose behavior (warning+), but enabled backtrace/diagnose and included {exception} in the format so ERROR/CRITICAL logs that include exceptions still print full tracebacks.
  • Updated startup to call uvicorn.run(..., log_config=None) in backend/start_alwrity_backend.py so Uvicorn does not override the unified logging configuration.

Testing

  • Ran python -m compileall backend/logging_config.py backend/start_alwrity_backend.py to validate syntax and byte-compile both modified modules, which completed successfully.
  • Confirmed local file diffs show the intended changes to backend/logging_config.py and backend/start_alwrity_backend.py and that the startup invocation includes log_config=None (no runtime tests were run as part of this change).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant