logging-design-patternslisted
Install: claude install-skill kookr-ai/kookr
# Logging Design Patterns
Rules for structured, secure, and cost-effective logging in production Node.js/TypeScript services.
**Research:** `docs/deepresearch/reports/Logging Design Best Practices.md`
## Non-Negotiable Rules
| # | Rule | Violation Example | Correct Pattern |
|---|------|-------------------|-----------------|
| 1 | **Structured JSON, never printf** | `` console.log(`User ${id} failed`) `` | `logger.info({ user_id: id, event: 'login_failed' })` |
| 2 | **snake_case log fields** | `{ userId, requestId }` | `{ user_id, request_id }` (OTel/Datadog convention) |
| 3 | **Strict log level semantics** | `logger.info('DB pool exhausted')` | `logger.warn({ pool_usage: 95 }, 'High DB pool usage')` |
| 4 | **Correlation ID on every log** | Log lines with no trace context | Include `trace_id` and `span_id` from OTel span |
| 5 | **Never log PII or secrets** | `logger.info({ body: req.body })` | Use `pino-redact` with explicit allowlist paths |
| 6 | **No console.log in production** | `console.log(data)` | `logger.info({ ... }, 'message')` |
| 7 | **Logs for events, metrics for aggregates** | `` logger.info(`took ${ms}ms`) `` | Emit histogram metric + log the discrete event |
| 8 | **AsyncLocalStorage for context** | Manually passing request_id through call chain | `als.run({ request_id }, () => next())` |
| 9 | **Never log 100% at high QPS** | Logging every request at INFO in hot paths | Tail-based sampling (errors + slow requests always) |
| 10 | **Canonical log line