Python logging.config dictConfig Setup Prompt
Configure Python's logging via a single declarative dictConfig dictionary with multiple handlers, formatters, and per-module log levels instead of scattered basicConfig calls
- Target user
- Python automation and backend engineers standardizing logging across a multi-module project
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior Python engineer who specializes in the standard library `logging` module and `logging.config.dictConfig`. I will provide: - My module/package layout and which loggers should exist (e.g. `app`, `app.db`, `app.http`) - The handlers I want (console, rotating file, JSON/syslog) and the level for each - Whether config should be inlined, loaded from YAML/JSON, or driven by an env var Your job: 1. **Build the dictConfig schema** — produce a complete `version: 1` dict with `formatters`, `handlers`, `loggers`, and `root` sections, fully populated. 2. **Set propagation correctly** — explain `propagate: false` on named loggers to prevent duplicate records reaching the root handler. 3. **Wire a rotating handler** — configure `logging.handlers.RotatingFileHandler` (or TimedRotating) with size/backupCount and explain the `()` custom-factory syntax if needed. 4. **Apply it once** — show the single `dictConfig(CONFIG)` call at startup and warn against calling `basicConfig` afterward. 5. **Support external config** — load the same dict from YAML/JSON and override the level from an env var (e.g. `LOG_LEVEL`). 6. **Verify** — give a tiny snippet that emits a record at each level so I can confirm formatters and routing. Output as: one Python module defining `CONFIG` and a `setup_logging()` function, plus an optional `logging.yaml` block. Flag explicitly any duplicate-log-line risk caused by both a named logger and root logging the same record.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Python Multi-Log Merge and Timeline Correlator Prompt
Build a Python tool that merges several log files with different timestamp formats into one time-ordered timeline, tags each line with its source, and correlates events across services for incident analysis
-
Bash Leveled Logging Library Prompt
Build a small, sourceable Bash logging library with DEBUG/INFO/WARN/ERROR levels, timestamps, TTY-aware color, and a LOG_LEVEL threshold — so your scripts emit consistent, greppable output to stderr.
-
Python Structured Logging for Automation Scripts Prompt
Add production-grade structured logging to a Python automation script — JSON logs, correlation IDs, levels, redaction of secrets, and rotation — so cron and systemd runs are debuggable after the fact.
-
Python Environment Config Drift Detector Prompt
Build a Python tool that compares configuration or environment-variable sets across environments (dev/staging/prod) and reports missing, extra, and mismatched keys while masking secret values
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.