Skip to content

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.py that 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 Task model and run an Alembic migration to update the database without losing data.