Structured Logging

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

aselimc Updated

File contents

Structured Logging

Standard Fields

Every log entry: timestamp, level, module, message, context

Python

import structlog
logger = structlog.get_logger()
logger.info("training_step", epoch=5, loss=0.42, lr=1e-4)

Or stdlib with JSON formatter:

import logging, json
logging.basicConfig(format='%(message)s')

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

aselimc/agents_and_skills/tree/main/.claude/skills/structured-logging commit e94c2e4ecd

Frequently asked questions

npx skillmds@latest add aselimc/structured-logging