structlog-structured-logging

structlog-structured-logging is a skill for Claude Code, Codex from DemboNauta/skill-doc-generator. It costs 61 tokens per session (4,120 once invoked), scanned A, original, MIT.

A guide to structlog, a Python library that records log events as structured data such as dictionaries instead of only plain text. The data can be rendered as JSON, logfmt, or readable console output.

In plain words
What is it for?
Use it when adding Python logging, configuring development or production output, carrying request-specific context, connecting to standard Python logging, or testing log behavior.
Why use it?
Structured records make application logs easier for people and software to search, filter, and process, while shared context can follow a request.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/dembonauta/skill-doc-generator/structlog-structured-logging
Any agent
npx skills add DemboNauta/skill-doc-generator --skill structlog-structured-logging
Clone the repo
git clone --depth 1 https://github.com/DemboNauta/skill-doc-generator

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for structlog-structured-logging

README.md
[![agentmods](https://agentmods.dev/badge/skills/dembonauta/skill-doc-generator/structlog-structured-logging.svg)](https://agentmods.dev/skills/dembonauta/skill-doc-generator/structlog-structured-logging)
Your own site
<a href="https://agentmods.dev/skills/dembonauta/skill-doc-generator/structlog-structured-logging"><img src="https://agentmods.dev/badge/skills/dembonauta/skill-doc-generator/structlog-structured-logging.svg" alt="Measured on agentmods" height="20"></a>
Per session 61 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,120 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00061 $0.04120
Opus 5 $0.00030 $0.02060
Sonnet 5 $0.00012 $0.00824
Haiku 4.5 $0.00006 $0.00412

Measured 4d ago against content hash 725f47de3ce9, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

structlog-structured-logging scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

examples/skills/structlog-structured-logging/SKILL.md · 624 lines

How it starts

The opening of the file, as written. The whole thing — 624 lines — stays where its author put it; the contents beside it link to each section on GitHub.

structlog — Structured Logging for Python

structlog turns log entries into dictionaries processed through a chain of functions, giving you structured output (JSON, logfmt, pretty console) without sacrificing performance. It has been in production since 2013 and supports threads, asyncio, and greenlets.

Why structlog over stdlib logging

stdlib logging structlog
String messages, hard to parse Key-value dictionaries, machine-readable
Global mutable state Immutable bound loggers, safe to pass around
Complex handler/formatter hierarchy Simple processor chain of plain callables
No built-in context propagation contextvars integration out of the box
Verbose boilerplate per file One get_logger() call per file

Installation

pip install structlog
# For pretty dev exceptions (recommended):
pip install structlog rich
# Windows only (for colors):
pip install structlog rich colorama

Core Concepts

Event dict

Every log call builds a dictionary (event_dict). Context bound via bind() is merged with the kwargs of the log call.

Processor chain

A list of callables, each with signature (logger, method_name, event_dict) -> event_dict. They run in order; the last one must return a string/bytes (the renderer).

Bound logger

The object returned by get_logger(). It's immutable — calling bind() returns a new logger. Use contextvars for mutable global context.


Basic Usage

import structlog

log = structlog.get_logger()

# Simple log
log.info("user_login", user_id=42, ip="1.2.3.4")
# → 2024-01-01 12:00:00 [info     ] user_login   user_id=42 ip=1.2.3.4

# Bind context to a local logger
log = log.bind(request_id="abc-123", user_id=42)
log.info("processing_started")
log.warning("slow_query", duration_ms=1500)
# Both entries include request_id and user_id automatically

# Unbind a key
log = log.unbind("user_id")

# Replace all context
log = log.new(request_id="new-456")

Read the full file on GitHub · 624 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 624 lines · 61 tokens per session scan A 725f47de3ce9

Subscribe to this mod's changes

structlog-structured-logging is a skill published in the GitHub repository DemboNauta/skill-doc-generator (9 stars, last pushed 4mo ago), licensed MIT. It adds 61 tokens to every session and 4,120 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories