8. Logging, Middleware & Schema Evolution
The previous chapter shaped the application's structure: shared dependencies, a centralized exception handler, and per-feature routers.
In this chapter we'll add logging and a schema evolution.
- Python Logging: Standard-library logging from one-line setup through structured output.
- Configuring Logging: A single
config.pythat owns settings and log configuration. - FastAPI Middleware: Wrap every request to time it and emit a log line, plus how middleware compares to the exception handler from the previous chapter.
- Schema Evolution: Add the
Taskmodel and run an Alembic migration to update the database without losing data.