logging-patterns
Skill2 starsChanged 8 days agoMITView on GitHub
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.
10 other projects use a version of this.
Adopted by
Most recently taken up by
- decebals/claude-code-javatheir own version, first seen Nov 1, 2026
- piomin/claude-ai-spring-boottheir own version, first seen Oct 25, 2026
- piomin/claude-ai-quarkustheir own version, first seen Oct 25, 2026
- mvonline/claude-skillstheir own version, first seen Oct 11, 2026
- Abdox-menara/guard-skillstheir own version, first seen Aug 24, 2026
- techdeveloper-org/mcp-jenkins-citheir own version, first seen Aug 12, 2026
Used with
Projects with it also use jpa-patterns, spring-boot and 2 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
mstuder-slalomSkilljpa-patterns
JPA/Hibernate patterns for entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and pooling in Spring Boot.
Also in 6 projects that use this
ffsshhttiikkSkillspring-boot
Spring Boot framework and Java enterprise patterns
Also in 3 projects that use this
zavierSkilljava-code-review
Java代码审查技能,通过比较两个git分支进行自动化代码审查
Also in 3 projects that use this
MicrosoftSkillcode-quality
Statically check changed C# against the same deterministic rules github-code-quality[bot] runs on pull requests, so a contributor can fix likely findings before opening the PR and keep the bot's inline comments to a minimum. Activate when a contributor asks to "check code quality", "run code quality on my changes", "will the code quality bot complain", "pre-check before I open the PR", "code quality check", or similar. Scoped to C#. Reads the diff and compares it against the enumerated csharp-code-quality rule set below — no CodeQL download or build required. This is a fast approximation of a dataflow engine, not a reproduction; report accordingly. Does NOT apply fixes unless explicitly asked.
Also in 3 projects that use this
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- piomin/claude-ai-spring-boot★ 1.4ksame name
- decebals/claude-code-java★ 763same name
- DIL8654/claude-code-dotnet-template★ 8same name
- piomin/claude-ai-quarkus★ 7same name
- iCesofT/awesome-ai★ 1same name
- piomin/spring-boot-app-with-claudecode★ 1same name
- Abdox-menara/guard-skills★ 0same name
- mvonline/claude-skills★ 0same name
- Nadav011/apex-skills★ 0same name
- techdeveloper-org/mcp-jenkins-ci★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository37 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- templates/CLAUDE.mdCLAUDE.md
- auditSkill
- backup-patternsSkill
- bash-patternsSkill
- depsSkill
- django-patternsSkill
- docker-patternsSkill
- drf-patternsSkill
- engineering-fundamentalsSkill
- fastapi-patternsSkill
- git-patternsSkill
- go-patternsSkill
- graphql-patternsSkill
- investigateSkill
- javascript-patternsSkill
- referenceSkill
- metaSkill
- monitoring-patternsSkill
- next-app-router-patternsSkill
- nuxt-patternsSkill
- opentofu-patternsSkill
- prSkill
- python-patternsSkill
- react-patternsSkill
- report-formatSkill
- security-patternsSkill
- slop-patternsSkill
- storybook-patternsSkill
- tailwind-patternsSkill
- test-patternsSkill
- typescript-patternsSkill
- unslopSkill
- vps-provisioningSkill
- vue-patternsSkill
- wcag-auditSkill
- writeSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 45
Use the a-prefixed calls (ainfo, aerror) in async code so rendering does not block the loop.
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Logging Patterns
Review checklist plus the configuration shapes that are easy to get wrong. Level semantics and handler constructors are in the stdlib docs.
stdlib gotchas
basicConfigis a no-op if the root logger already has handlers. Call it once at the entry point; passforce=Trueto replace existing handlers (useful in tests).- Records propagate up the dot-separated hierarchy to parent handlers. Set
propagate = Falseonly when you have deliberately attached a handler to that logger; otherwise you get every record twice. - Silence a noisy dependency by name rather than lowering the global level:
logging.getLogger("httpx").setLevel(logging.WARNING).
structlog configuration
The processor chain is order-sensitive and the API shifts between minor versions: pin this shape and verify against the docs on upgrade.
import logging
import structlog
structlog.configure(
processors=[
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(fmt="iso", utc=True),
structlog.dev.ConsoleRenderer(), # JSONRenderer() in production
],
wrapper_class=structlog.make_filtering_bound_logger(logging.DEBUG),
logger_factory=structlog.PrintLoggerFactory(),
cache_logger_on_first_use=True,
)- Request-scoped context that survives awaits and task boundaries goes through
structlog.contextvars.bind_contextvars(...), whichmerge_contextvarsfolds into every record.logger.bind(...)returns a new logger and does not cross task boundaries. - Use the
a-prefixed calls (ainfo,aerror) in async code so rendering does not block the loop. structlog.stdlib.recreate_defaults()routes structlog through stdlib logging, needed when third-party libraries log too.
Anti-patterns
failure: f-strings in log calls
logger.warning(f"msg: {a}") interpolates even when the record is filtered out. Use logger.warning("msg: %s", a) for stdlib, or logger.warning("msg", key=a) for structlog.
failure: bare except with logging.exception inside a loop Catching all exceptions and logging them without re-raising hides bugs in long-running loops. Either re-raise or catch a specific exception type.
warning: configuring logging inside library code
Libraries must not call basicConfig, addHandler, or setLevel at module level. Configure only in the application entry point. Libraries add a NullHandler to their top-level logger and nothing else.
warning: print() for diagnostic output in server code
print bypasses handlers, formatters, and level filters. Replace with a logger at the appropriate level.
warning: root logger used directly in library modules
logging.info(...) logs to the root logger and cannot be scoped or silenced per-module. Always use logging.getLogger(__name__).
info: no structured context on error logs
Plain string messages like "payment failed" are hard to aggregate. Add identifiers: logger.error("payment.failed", order_id=order.id, amount=amount).
References
- https://docs.python.org/3/library/logging.html
- https://docs.python.org/3/howto/logging.html
- https://www.structlog.org/en/stable/getting-started.html
Verify structlog processor names and configuration shape against the structlog docs when upgrading, as the processor API evolves between minor versions.
Version notes
Checked: 2026-09-26 against https://pypi.org/project/structlog/, https://www.structlog.org/en/stable/api.html, https://docs.python.org/3/library/logging.html
- structlog 26.1.0 (2026-06-06): requires Python >= 3.10; no change to the processors used here. Python 3.14.7 current.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

