← ClaudeAtlas

logging-patternslisted

Python logging patterns covering stdlib logging configuration, structured logging with structlog, log levels, handlers, formatters, and context binding. Use whenever a project uses Python logging, structlog, or the user asks about log levels, log formatting, structured logs, or JSON logging, even if "logging" is not mentioned by name.
ku5ic/dotfiles · ★ 0 · Data & Documents · score 72
Install: claude install-skill ku5ic/dotfiles
# Logging Patterns ## When to load this skill - Python project with `import logging` or `import structlog` - User asks about log levels, log formatting, structured logs, or JSON logging - User asks why logs appear twice or why a logger is silent - User is configuring a logging handler, formatter, or filter ## When not to load this skill - JavaScript/Node.js logging (pino, winston, console) - Infrastructure log aggregation configuration (Loki, Elasticsearch) --- ## stdlib logging ### Logger setup Get a module-level logger. Never use the root logger directly in library code. ```python import logging logger = logging.getLogger(__name__) ``` ### Log levels | Level | Value | When to use | | -------- | ----- | ------------------------------------- | | DEBUG | 10 | Detailed diagnostic info, dev only | | INFO | 20 | Routine operational events | | WARNING | 30 | Something unexpected but recoverable | | ERROR | 40 | Operation failed, execution continues | | CRITICAL | 50 | Application cannot continue | ### Application bootstrap (call once at startup) ```python import logging logging.basicConfig( level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s", datefmt="%Y-%m-%dT%H:%M:%S", ) ``` `basicConfig` only takes effect if the root logger has no handlers. Call it exactly once at the entry point. Pass `force=True` to replace existing handlers (useful in tests). #