# Structured Logging

> JSON-structured logging with consistent fields and correlation IDs across services.

- Skill: `aselimc/structured-logging` (Agent Skill)
- Install (CLI): `npx skillmds@latest add aselimc/structured-logging`
- Raw SKILL.md: https://api.skillmd.com/api/skills/aselimc/structured-logging/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: aselimc (https://skillmd.com/u/aselimc)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/aselimc/structured-logging

---


# Structured Logging

## Standard Fields
Every log entry: `timestamp`, `level`, `module`, `message`, `context`

## Python
```python
import structlog
logger = structlog.get_logger()
logger.info("training_step", epoch=5, loss=0.42, lr=1e-4)
```
Or stdlib with JSON formatter:
```python
import logging, json
logging.basicConfig(format='%(message)s')
```

## Node.js
```js
import pino from 'pino';
const logger = pino();
logger.info({ epoch: 5, loss: 0.42 }, 'training_step');
```

## Rules
- JSON format in production, human-readable in dev
- Include correlation/request IDs for distributed traces
- Log levels: DEBUG (dev only), INFO (normal ops), WARNING (degraded), ERROR (failures), CRITICAL (system down)
- Never log secrets, tokens, or PII

