Overview
Establishes centralized, structured logging for production systems. Covers JSON log format, log level guidelines, shipping options (Fluentd, Promtail, Vector, Filebeat), storage backends (ELK, Loki + Grafana, CloudWatch, Datadog), retention policies, and basic alerting on error rate or anomaly patterns. Includes code examples for Node.js, Python, and Go.
When to Use This Skill
- Moving from local file logs or
console.log to a proper observability stack.
- Debugging production issues that require historical logs.
- Meeting compliance or audit requirements.
Prerequisites
- Applications that can emit structured logs.
- A logging backend (self-hosted or SaaS).
- Network access from apps to the log shipper/collector.
Steps
Adopt structured logging:
- Use a library that outputs JSON (pino for Node, structlog or logging with json formatter for Python, zap for Go).
- Include standard fields:
timestamp, level, message, service, trace_id, user_id (when available), error.
Log level policy:
- ERROR: Something broke, needs attention.
- WARN: Degraded but recovered.
- INFO: Normal business events.
- DEBUG: Detailed for local/dev only (never in prod by default).
Choose shipping architecture:
- Sidecar / DaemonSet (Promtail for Loki, Fluent Bit).
- Direct from app (for cloud providers).
- Agent on host.
Storage & query:
- Loki + Grafana (lightweight, labels + LogQL).
- ELK (full text search, Kibana).
- Cloud native (CloudWatch Logs, GCP Logging).
Retention & cost:
- Hot/warm/cold tiers.
- 30-90 days hot, longer in cold storage or S3.
Alerting:
- High error rate (>1% or threshold).
- Sudden spike in logs (possible loop).
- Specific error strings (e.g., "OutOfMemory").
Output:
- Structured logger config for 2-3 languages.
- Docker / Kubernetes log shipping config (Promtail example).
- Basic Grafana dashboard for logs + error rate.
- Retention and alert rule examples.
Examples
Pino logger setup for Node, structlog for Python, Promtail config for Kubernetes, and a simple Loki alert rule are included.
Edge Cases & Error Handling
- High cardinality labels: Avoid putting user IDs or request IDs in labels in Loki (use in message or indexed fields carefully).
- Sensitive data: Never log passwords, tokens, PII. Use log redaction middleware.
- Log volume explosion: Sample debug logs in prod or use dynamic levels.
Verification
- Deploy the logger + shipper.
- Generate traffic and errors.
- Query logs in the backend by service, level, trace_id.
- Confirm an alert fires on injected errors.
- Success: All services emit consistent JSON logs, they are queryable centrally, and critical errors are alerted.
References
1---2name: log-aggregator-setup3description: Sets up centralized log aggregation with structured logging, log levels, and alerting. Use when implementing observability in production systems.4license: Apache-2.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: devops10 tags: logging, observability, elk, loki, grafana, structured-logging, fluentd11---1213## Overview1415Establishes centralized, structured logging for production systems. Covers JSON log format, log level guidelines, shipping options (Fluentd, Promtail, Vector, Filebeat), storage backends (ELK, Loki + Grafana, CloudWatch, Datadog), retention policies, and basic alerting on error rate or anomaly patterns. Includes code examples for Node.js, Python, and Go.1617## When to Use This Skill1819- Moving from local file logs or `console.log` to a proper observability stack.20- Debugging production issues that require historical logs.21- Meeting compliance or audit requirements.2223## Prerequisites2425- Applications that can emit structured logs.26- A logging backend (self-hosted or SaaS).27- Network access from apps to the log shipper/collector.2829## Steps30311. **Adopt structured logging**:32 - Use a library that outputs JSON (pino for Node, structlog or logging with json formatter for Python, zap for Go).33 - Include standard fields: `timestamp`, `level`, `message`, `service`, `trace_id`, `user_id` (when available), `error`.34352. **Log level policy**:36 - ERROR: Something broke, needs attention.37 - WARN: Degraded but recovered.38 - INFO: Normal business events.39 - DEBUG: Detailed for local/dev only (never in prod by default).40413. **Choose shipping architecture**:42 - Sidecar / DaemonSet (Promtail for Loki, Fluent Bit).43 - Direct from app (for cloud providers).44 - Agent on host.45464. **Storage & query**:47 - Loki + Grafana (lightweight, labels + LogQL).48 - ELK (full text search, Kibana).49 - Cloud native (CloudWatch Logs, GCP Logging).50515. **Retention & cost**:52 - Hot/warm/cold tiers.53 - 30-90 days hot, longer in cold storage or S3.54556. **Alerting**:56 - High error rate (>1% or threshold).57 - Sudden spike in logs (possible loop).58 - Specific error strings (e.g., "OutOfMemory").59607. **Output**:61 - Structured logger config for 2-3 languages.62 - Docker / Kubernetes log shipping config (Promtail example).63 - Basic Grafana dashboard for logs + error rate.64 - Retention and alert rule examples.6566## Examples6768Pino logger setup for Node, structlog for Python, Promtail config for Kubernetes, and a simple Loki alert rule are included.6970## Edge Cases & Error Handling7172- **High cardinality labels**: Avoid putting user IDs or request IDs in labels in Loki (use in message or indexed fields carefully).73- **Sensitive data**: Never log passwords, tokens, PII. Use log redaction middleware.74- **Log volume explosion**: Sample debug logs in prod or use dynamic levels.7576## Verification77781. Deploy the logger + shipper.792. Generate traffic and errors.803. Query logs in the backend by service, level, trace_id.814. Confirm an alert fires on injected errors.825. Success: All services emit consistent JSON logs, they are queryable centrally, and critical errors are alerted.8384## References8586- [Pino](https://github.com/pinojs/pino)87- [Loki + Promtail](https://grafana.com/docs/loki/latest/)88- [Fluent Bit](https://fluentbit.io/)89- [Structured Logging](https://www.structlog.org/en/stable/)