← Back to all products
$19
Python Logging & Config
Structured logging with structlog, environment-based configuration, secrets management, and 12-factor app patterns.
JSONMarkdownYAMLPythonFastAPIDjangoFlask
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 16 files
python-logging-config/
├── LICENSE
├── README.md
├── configs/
│ ├── logging_dev.yaml
│ ├── logging_prod.yaml
│ └── logging_test.yaml
├── examples/
│ ├── celery_example.py
│ └── fastapi_example.py
├── guides/
│ └── logging-guide.md
├── src/
│ ├── context.py
│ ├── filters.py
│ ├── formatters.py
│ ├── handlers.py
│ ├── middleware.py
│ └── setup.py
└── tests/
└── test_logging.py
📖 Documentation Preview README excerpt
Python Logging Config — Production-Ready Logging Setup
Structured logging, request context, ASGI/WSGI middleware, and environment-specific configs in one drop-in package.
What You Get
- One-call setup —
configure_logging("prod")loads the right YAML config - Structured JSON formatter — machine-readable logs for Datadog, ELK, CloudWatch
- Request context — automatic
request_id,user_idin every log line - ASGI & WSGI middleware — plug into FastAPI, Starlette, Flask, Django
- Smart filters — suppress noisy loggers, rate-limit repeated messages
- 3 YAML configs — dev (colorized console), prod (JSON to file + stdout), test (minimal)
File Tree
python-logging-config/
├── README.md
├── manifest.json
├── LICENSE
├── src/
│ ├── setup.py # One-call logging configuration
│ ├── formatters.py # JSON, colored, and key-value formatters
│ ├── handlers.py # Rotating file, async queue handler
│ ├── context.py # Context variables (request_id, user_id)
│ ├── middleware.py # ASGI and WSGI middleware
│ └── filters.py # Rate-limit and suppression filters
├── configs/
│ ├── logging_dev.yaml # Development config
│ ├── logging_prod.yaml # Production config
│ └── logging_test.yaml # Test config
├── examples/
│ ├── fastapi_example.py # FastAPI integration
│ └── celery_example.py # Celery task logging
├── tests/
│ └── test_logging.py
└── guides/
└── logging-guide.md
Getting Started
Quick setup
from src.setup import configure_logging
configure_logging("dev") # Colorized console output
import logging
logger = logging.getLogger(__name__)
logger.info("Application started")
Structured JSON logging (production)
configure_logging("prod")
logger.info("Order placed", extra={"order_id": "ORD-123", "total": 49.99})
# {"timestamp": "2026-03-10T12:00:00Z", "level": "INFO", "message": "Order placed", "order_id": "ORD-123", ...}
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/setup.py"""One-call logging configuration.
Usage:
from src.setup import configure_logging
configure_logging("dev") # Colorized console
configure_logging("prod") # JSON to file + stdout
configure_logging("test") # Minimal output
"""
from __future__ import annotations
import logging
import logging.config
from pathlib import Path
from typing import Any
import yaml
CONFIGS_DIR = Path(__file__).resolve().parent.parent / "configs"
_VALID_ENVS = {"dev", "prod", "test"}
def configure_logging(
env: str = "dev",
*,
config_dir: str | Path | None = None,
overrides: dict[str, Any] | None = None,
) -> None:
"""Configure the Python logging system from a YAML config file.
Loads ``logging_{env}.yaml`` from the configs directory and applies
it via :func:`logging.config.dictConfig`.
Args:
env: Environment name — ``"dev"``, ``"prod"``, or ``"test"``.
config_dir: Override the default configs directory.
overrides: Dictionary of overrides merged into the loaded config.