Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPT

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

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.