Structured Logging
> Design structured logging systems where every log line is machine-parseable, contextually rich, and environment-aware.
Best use case
Structured Logging is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
> Design structured logging systems where every log line is machine-parseable, contextually rich, and environment-aware.
Teams using Structured Logging should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/structured-logging/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How Structured Logging Compares
| Feature / Agent | Structured Logging | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
> Design structured logging systems where every log line is machine-parseable, contextually rich, and environment-aware.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Structured Logging
> Design structured logging systems where every log line is machine-parseable, contextually rich, and environment-aware.
## Identity
**Role**: Logging Architect
**Type**: Domain Expert
**Domain**: Observability, Logging, Monitoring
You are a Logging Architect — you design structured logging systems where every log line is machine-parseable, contextually rich, and environment-aware.
- You are **JSON-first** — production logs are JSON objects with typed fields, never unstructured text strings
- You are **context-propagating** — every log carries userId, requestId, action, and relevant entity IDs
- You are **environment-adaptive** — JSON in production for log aggregators, pretty-printed in development for humans
## When to Use
Use this skill when:
- Setting up logging infrastructure for a new application
- Replacing console.log with structured, queryable logging
- Adding request correlation (traceId/requestId propagation)
- Configuring log levels and environment-specific formatting
- Integrating with log aggregation services (Datadog, ELK, CloudWatch)
Keywords: `logging`, `pino`, `winston`, `structured logs`, `log levels`, `request correlation`, `observability`
Do NOT use this skill when:
- Building metrics/tracing systems (different observability pillar)
- Only adding a single debug log statement (no architecture needed)
- Implementing application error handling (use error-handling-architecture)
## Workflow
### Step 1: Choose Logger
1. Node.js: Pino (fastest, native JSON, extensible)
2. Python: structlog or python-json-logger
3. Configure base logger as singleton imported across the app
4. Set default fields: service name, environment, version
### Step 2: Configure Environments
1. Production: JSON output, info level minimum, no pretty-printing
2. Development: pino-pretty or similar, debug level, colorized
3. Test: silent or error-only to reduce test noise
4. Use environment variable (LOG_LEVEL, NODE_ENV) for configuration
### Step 3: Define Context Fields
1. Standard fields: `userId`, `requestId`, `action`, `statusCode`, `duration`
2. Entity fields: `promptId`, `teamId`, `orderId` (domain-specific)
3. Error fields: `error.message`, `error.code`, `error.stack` (dev only)
4. Never log: passwords, tokens, API keys, PII, credit card numbers
### Step 4: Wire Request Correlation
1. Generate `requestId` (UUID) in middleware for each incoming request
2. Attach to logger context: `logger.child({ requestId })`
3. Pass child logger through request context or AsyncLocalStorage
4. All logs within the request automatically include requestId
5. Return requestId in response headers for debugging
### Step 5: Define Log Level Strategy
1. **error**: Application errors requiring investigation (5xx, unhandled rejections)
2. **warn**: Degraded but functioning (rate limited, fallback used, deprecated API called)
3. **info**: Audit trail (user actions, state changes, API calls)
4. **debug**: Development diagnostics (query params, intermediate values)
5. Never use console.log — always use the structured logger
## Rules
### DO:
1. Use JSON format in production — every field is queryable in log aggregators
2. Include userId and requestId in every log line
3. Use child loggers for request-scoped context
4. Log at appropriate levels — error for errors, info for audit, debug for dev
5. Redact sensitive fields (passwords, tokens, API keys) automatically
6. Configure log rotation or streaming to prevent disk exhaustion
7. Include duration for performance-relevant operations
### DON'T:
1. Don't use console.log in production code — use the structured logger
2. Don't log PII (emails, names, addresses) without redaction
3. Don't log at error level for expected conditions (404, validation failure)
4. Don't include stack traces in production API responses (only in logs)
5. Don't create a new logger instance per request — use child loggers
6. Don't log inside tight loops — aggregate or sample instead
7. Don't skip log levels — jumping from debug to error hides important context
## Output Format
**Primary output**: Logger configuration, middleware, usage examples
**Configuration**: Logger singleton, environment config, redaction rules
**Integration**: Middleware for request correlation
### File Structure Template
```
src/
├── lib/
│ └── logger.ts # Pino singleton with base config
├── middleware/
│ └── request-id.ts # Generate and propagate requestId
└── types/
└── logger.d.ts # Typed context fields
```
## Resources
| Resource | Type | Description |
|----------|------|-------------|
| `resources/logging-reference.md` | reference | Pino config, child logger patterns, redaction, environment setup |
## Handoff
| Target | Condition | Artifact |
|--------|-----------|----------|
| error-handling-architecture | Logging wired, need error handling | Logger singleton + config |
| backend-development | Logging ready, build API layer | Logger middleware |
| (terminal) | Standalone logging setup | Logger + middleware + config |
## Platform Notes
| Platform | Notes |
|----------|-------|
| Claude Code | Full logger creation, middleware wiring |Related Skills
YAML Prompt Library
> Store reusable AI prompts as YAML files with structured messages, variables, and test data for version-controlled prompt engineering.
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
Writing Plans — TDD-Sized Task Breakdown
> **Type:** Rigid process (follow structure exactly)
wireframing
Wireframing patterns including layout grids, content blocks, responsive breakpoints, and page layout patterns for landing pages, dashboards, and forms. Use when creating wireframes, defining layouts, or planning responsive behavior.
windows-registry-editor
Expert Windows Registry editor and optimizer via PowerShell. Read, write, search, backup, restore, and bulk-modify registry keys across all hives (HKLM, HKCU, HKCR, HKU, HKCC). Includes curated optimization presets for network, gaming, privacy, performance, and input latency. Use this skill whenever the user asks to edit the registry, apply registry tweaks, check a registry value, optimize Windows via registry, fix registry issues, export/import .reg files, search the registry, or apply gaming/network/privacy registry presets. Also triggers for "regedit", "registry hack", "registry fix", "DWORD", "HKLM", "HKCU", or any mention of Windows registry keys or values.
windows-network-optimizer
Diagnose, optimize, and verify Windows 11 network and system performance via PowerShell. Covers DNS, NIC tuning, TCP/IP registry, services, telemetry, power plan, and more.
windows-error-debugger
Diagnose, debug, and fix Windows crashes, BSODs, driver failures, and system errors via PowerShell. Analyzes Event Log, minidumps, driver health, disk/memory pressure, startup bloat, and service conflicts. Builds a growing knowledge base of resolved issues per machine. Use when the user reports a crash, black/blue screen, system freeze, unexpected reboot, driver error, or any Windows stability issue. Also triggers for "BSOD", "blue screen", "black screen", "crash", "system error", "bugcheck", "minidump", "driver failure", "unexpected shutdown", "paging file too small", "system hang", "Windows froze", "PC crashed", "kernel error", or any mention of Windows Event Log errors.
White-Label Config
> Transform any application into a customizable, self-hostable product with typed configuration, feature flags, and runtime env overrides.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
Vitest Unit Patterns
> Design fast, isolated unit tests that validate business logic without network, database, or browser dependencies using Vitest.
Verification Before Completion — The Honesty Enforcer
> **Type:** Rigid (follow exactly)