Guide Home Part 1 - FastAPI Foundations Part 2 - Building Applications Part 3 - Pages and HTML Part 4 - Security and Deployment Part 5 - Going Further Capstone Build Plan Markdown Source All Guides

Chapter 26: Logging and Troubleshooting

ASP.NET Core has structured logging abstractions. Python has standard logging, plus libraries such as structlog and loguru. For production services, prefer standard logging plus structured output.

import logging

logger = logging.getLogger(__name__)


def publish_recipe(recipe_id: int, user_id: int) -> None:
    logger.info(
        "Publishing recipe",
        extra={"recipe_id": recipe_id, "user_id": user_id},
    )

Production logging practices:

Troubleshooting Python apps also means understanding import paths, virtual environments, process managers, worker counts, and environment variables. Many "framework bugs" are actually deployment shape bugs.