Skip to content

Feature: Log to File - #82

Merged
rosemcc merged 6 commits into
mainfrom
feature/log-to-file
Aug 20, 2026
Merged

Feature: Log to File#82
rosemcc merged 6 commits into
mainfrom
feature/log-to-file

Conversation

@rosemcc

@rosemcc rosemcc commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces centralized API request logging with correlation IDs, file-based log rotation, and tests for logging behavior. The changes enhance observability by ensuring all API requests and exceptions are consistently logged, and allow for durable log retention via rotating file handlers.

API Logging and Observability:

  • Added a FastAPI middleware that logs all API requests with method, path, status code, latency, and correlation/request IDs; also logs unhandled exceptions with a consistent JSON 500 response and centralized log event. (src/api/main.py)
  • Integrated the asgi-correlation-id package to propagate request IDs across logs and responses, and ensured the X-Request-ID header is included in all API responses. (pyproject.toml, src/api/main.py, src/utils/logging.py) [1] [2] [3]

File Logging and Configuration:

  • Implemented rotating file log support with configuration options for file path, rotation timing, interval, and retention count; file logging is best-effort and falls back to stdout if setup fails. (src/utils/logging.py, src/config.py, README.md, src/api/README.md) [1] [2] [3] [4]

Testing and Reliability:

  • Added tests to verify API logging middleware behavior, including request completion and exception handling, ensuring correlation IDs and error details are logged as expected. (tests/test_api_logging.py)
  • Added tests for logging configuration to ensure only a single file handler is added and that stdout logging remains active if file handler setup fails. (tests/test_logging_config.py)

@rosemcc
rosemcc merged commit dbbf2d0 into main Aug 20, 2026
1 check passed
@rosemcc
rosemcc deleted the feature/log-to-file branch August 20, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant