agentleFS
ku5icku5ic/claude-kit/skills/logging-patterns/SKILL.md

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

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-slalomSkill

    jpa-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

  • ffsshhttiikkSkill

    spring-boot

    Spring Boot framework and Java enterprise patterns

    Also in 3 projects that use this

  • zavierSkill

    java-code-review

    Java代码审查技能,通过比较两个git分支进行自动化代码审查

    Also in 3 projects that use this

  • MicrosoftSkill

    code-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

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
  1. Very specific:

    Use the a-prefixed calls (ainfo, aerror) in async code so rendering does not block the loop.

    line 45

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  • basicConfig is a no-op if the root logger already has handlers. Call it once at the entry point; pass force=True to replace existing handlers (useful in tests).
  • Records propagate up the dot-separated hierarchy to parent handlers. Set propagate = False only 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(...), which merge_contextvars folds 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

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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.