structured-logging

structured-logging is a skill for Claude Code, Codex from cass-2003/local-workflow-skill. It costs 152 tokens per session (3,197 once invoked), scanned A, original, MIT.

A guide to structured application logging, where programs write consistent JSON records with fields such as severity, service, request IDs, and trace IDs. It also covers sending logs to storage and search systems and removing personal data.

In plain words
What is it for?
Use it to define log formats, choose logging libraries, connect logs with metrics and traces, pass request context across services, and protect sensitive fields.
Why use it?
It makes logs easier for machines and people to search across services while reducing problems such as inconsistent fields, missing request context, exposed personal data, and excessive log volume.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to define log formats, choose logging libraries, connect logs with metrics and traces, pass request context across services, and protect sensitive fields.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/cass-2003/local-workflow-skill/structured-logging
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.

Any agent
npx skills add cass-2003/local-workflow-skill --skill structured-logging
Clone the repo
git clone --depth 1 https://github.com/cass-2003/local-workflow-skill

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 structured-logging

README.md
[![agentmods](https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/structured-logging/github.svg)](https://agentmods.dev/skills/cass-2003/local-workflow-skill/structured-logging)
Your own site
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/structured-logging"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/structured-logging/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for structured-logging

Your own site · 80×15
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/structured-logging"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/structured-logging.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 152 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,197 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00152 $0.03197
Opus 5 $0.00076 $0.01598
Sonnet 5 $0.00030 $0.00639
Haiku 4.5 $0.00015 $0.00320

Measured 7d ago against content hash 9a345dd37c82, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

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

skills/engineering-core/ours/structured-logging/SKILL.md · 338 lines

How it starts

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

Structured Logging Skill — 结构化日志

何时使用

  • 新项目立项(日志格式从一开始定型)
  • 调试"为什么 SRE 让我加 trace ID"
  • 处理"日志体积爆炸 / 检索缓慢"
  • 排查跨服务调用的请求链路
  • 满足合规(PII / GDPR)的日志脱敏

一、核心原则

  1. 机器优先:JSON 格式,键值对。人类用 jq / Loki / ES query 看
  2. 每条日志带 context:service / version / env / trace_id / user_id / request_id
  3. 大写 level 严格语义:DEBUG < INFO < WARN < ERROR < FATAL
  4. 永不日志即吞噬:catch 后必须含 cause 或 rethrow
  5. 结构化字段稳定:键名固定、不要混用 userId / user_id / uid
  6. PII 默认脱敏:邮件 / 手机 / 身份证 / 卡号永远过滤 redactor

二、JSON 日志标准字段

{
  "ts": "2026-05-06T07:00:00.123Z",
  "level": "info",
  "service": "checkout-api",
  "version": "v2.3.1",
  "env": "production",
  "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
  "span_id": "00f067aa0ba902b7",
  "request_id": "req_abc123",
  "user_id": "u_456",
  "msg": "order created",
  "order_id": "ord_789",
  "amount_cents": 12345,
  "currency": "USD",
  "duration_ms": 87
}

字段约定

  • ts ISO 8601 UTC(带 Z)
  • level 小写:debug / info / warn / error / fatal
  • msg 简短描述(不含变量值;变量在结构化字段里)
  • trace_id / span_id 遵循 W3C Trace Context(OpenTelemetry 标准)

反模式

// ❌ 字符串拼接
{ "msg": "user 123 created order 456 for $123.45" }

// ✅ 结构化
{ "msg": "order created", "user_id": 123, "order_id": 456, "amount_cents": 12345 }

理由:检索 user_id=123 比正则匹配 string 快几个数量级,且不受 msg 文案变化影响。

三、Log Level 语义(严格)

Level 含义 例子 生产开启?
DEBUG 开发诊断 "entering function X with args"
INFO 正常事件 "user logged in" / "order created"
WARN 异常但已恢复 "retrying after 5xx" / "fallback to cache"
ERROR 失败需关注 "DB query failed" / "5xx returned" ✅(有告警)
FATAL 进程终止 "config invalid, shutting down" ✅(罕见)

关键

  • ERROR 应触发告警 → 慎用,不要给瞬时网络抖动打 ERROR
  • INFO 日志 = 业务事件;不是函数追踪(用 trace 替代)
  • DEBUG 日志生产关闭,但保留代码(dev / staging 启用)

四、Context 透传

Go (1.21+ slog)

import "log/slog"

logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))

// 带 context 的 logger(每个请求基础信息)
reqLogger := logger.With(
    "request_id", reqID,
    "user_id", userID,
    "trace_id", traceID,
)

reqLogger.Info("order created", "order_id", orderID, "amount_cents", 12345)

Read the full file on GitHub · 338 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. 7d ago First seen · 338 lines · 152 tokens per session scan A 9a345dd37c82

Subscribe to this mod's changes

structured-logging is a skill published in the GitHub repository cass-2003/local-workflow-skill (12 stars, last pushed 2mo ago), licensed MIT. It adds 152 tokens to every session and 3,197 once invoked, about $0.0008 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-09-03.

Related

Other skills, from other repositories

debug-optimize-lcp

Guides debugging and optimizing Largest Contentful Paint (LCP) using Chrome DevTools MCP tools. Use this skill whenever the user asks about LCP performance, slow page loads, Core Web Vitals optimization, or wants to understand why their page's main content takes too long to appear. Also use when the user mentions…

ChromeDevTools/chrome-devtools-mcp · 99 tokens

systematic-debugging

Use when debugging a failing test, build error, or runtime issue that isn't immediately obvious. Guides a 4-phase root cause analysis instead of random fix attempts.

open-metadata/OpenMetadata · 37 tokens

diagnose

Trace from a reproduced symptom to the source code that causes it. Pin the specific file and approximate line, rate confidence in the cause and clarity of the fix independently, and always propose a concrete fix.

emdash-cms/emdash · 43 tokens

repro-admin

Reproduce an EmDash admin UI bug. Attach a container, start the demo dev server, drive the admin with agent-browser using the dev-bypass session, and capture the reproduction as screenshots plus a replayable transcript.

emdash-cms/emdash · 48 tokens

log-error-digest

Analyze log files to troubleshoot errors, identify peak error periods, and produce error clustering, frequency statistics, and time distribution reports. Supports JSON, syslog, and Nginx formats with automatic detection. Use when a user uploads a .log file and asks to analyze errors, find patterns, debug issues, or…

zebbern/claude-code-guide · 71 tokens

byted-util-volcengine-detect-retry

An orchestration workflow for Volcengine Cloud Detect, a service that checks websites or network endpoints from test locations.

bytedance/agentkit-samples · 101 tokens