一键导入
logging-patterns
Logging conventions -- level usage, formatting style, structured output.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Logging conventions -- level usage, formatting style, structured output.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
How agents, skills, and commands work in Claude Code projects.
GitHub conventions -- branch naming, commit format, issue/PR templates, and safe issue/PR referencing in comments.
API error response format -- machine-readable codes, human-readable reasons, status code rules.
Language-agnostic code hygiene -- honest comments, no dead/reinvented/duplicated code, truthful names, real implementations, and scoped (never blanket) diagnostic suppressions.
Language-agnostic structural craft -- decompose on responsibility not size, prefer deep modules over shallow piles, and shape cohesion, coupling, interfaces, error contracts, and data invariants. Sibling to code-hygiene and readable-code.
Documentation writing conventions -- style, structure, tone, and quality standards.
| name | logging-patterns |
| description | Logging conventions -- level usage, formatting style, structured output. |
| when_to_use | Writing code that logs events, configuring log output, or choosing log levels. |
One logger per module, at module level:
import logging
logger = logging.getLogger(__name__)
Use %s-style formatting arguments, not f-strings -- the message template is preserved for structured aggregator queries:
logger.info("Cleaned up %d expired sessions", count) # yes
logger.exception("SMTP send failed for %s", email) # yes (in an except handler)
logger.info(f"Cleaned up {count} expired sessions") # no
%s deferral is stdlib-specific -- structlog uses kwargs, not %s. See pythonica:python-observability.
| Level | Use for |
|---|---|
DEBUG | Cache hit/miss, slow-path internals (opt-in only) |
INFO | Startup/shutdown, admin bootstrap, cleanup counts, rate limit hits |
WARNING | Recoverable anomalies, swallowed exceptions, degraded operation |
ERROR | Unexpected exceptions on operational paths -- use logger.exception(...) |
CRITICAL | Reserved for unusable state |
Log to stderr when stdout carries the program's own output -- the common case: CLIs, filters, pipeline stages (also Python's logging.StreamHandler default). Use stdout only for pure log-shipping services that emit nothing else. One record per line either way. Container runtimes (Docker, k8s) capture both streams, so the choice isolates logs from program output, not runtime visibility -- no file sinks or log rotation in-app.
Support two formats via config:
plain -- Readable for local devjson -- Stable single-line object per record for log aggregators (Loki, Datadog, ELK, CloudWatch)Timestamps in UTC in both formats.