logging-best-practices · mindrally — Claude Code skill: structured logs, done
A skill that spells out logging rules: structured JSON, log levels, shared fields and request context. Useful when every service logs its own way.
npx skills add Mindrally/skills --skill logging-best-practices -a claude-codeWhat logging-best-practices does
The skill covers how applications and services should write logs. The core rule is structured JSON output with a consistent field set: timestamp in ISO 8601 with timezone, level, message, service, version, trace_id, span_id, request_id. String concatenation for messages is out; structured fields are in.
Levels get defined by intent: DEBUG for development diagnostics, INFO for normal events, WARN for handled surprises, ERROR for failures that hit the current operation, FATAL for critical ones. Request context should travel through MDC or an equivalent, and trace IDs cross service boundaries. A separate section handles security — passwords, tokens and PII stay out of logs, and anything that must be referenced gets masked.
Performance and aggregation are covered too: async logging, sampling DEBUG in production, rotation, centralized collection, alerts on critical patterns. Environment config is split — DEBUG and console output in development, structured JSON in staging and production. Treat it as a checklist rather than a library: it ships no logging code, so before adopting it, check that your logger can actually emit structured output and carry context.
What it helps with
- agree on one field set across all service logs
- sort events into levels without mixing up WARN and ERROR
- carry trace IDs across service boundaries
- keep passwords and PII out of logs and mask the rest
- sample DEBUG logs so production stays readable
Example prompts for the agent
- review the logging in this service against logging-best-practices
- rewrite these logger calls as structured JSON with trace_id and request_id
- what's wrong with the log levels here — go through logging-best-practices
How to install logging-best-practices
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill logging-best-practices -a claude-code2Manually: put the files in place
~/.claude/skills/logging-best-practices/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/logging-best-practices/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill logging-best-practices -a codex2Manually: put the files in place
.agents/skills/logging-best-practices/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill logging-best-practices -a cursor2Manually: put the files in place
.cursor/skills/logging-best-practices/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills logging-best-practices2Manually: put the files in place
.github/skills/logging-best-practices/SKILL.md1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill logging-best-practices -a gemini-cli2Platform CLI
gemini skills install https://github.com/Mindrally/skills --path logging-best-practicesManually: put the files in place
.devin/skills/logging-best-practices/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Mindrally/skills --skill logging-best-practices -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about logging-best-practices
How do I install logging-best-practices in Claude?
Run npx skills add Mindrally/skills --skill logging-best-practices -a claude-code. The skill lands in ~/.claude/skills/logging-best-practices/SKILL.md.
What does logging-best-practices do?
It lays out logging rules for applications and services: structured JSON, standard fields, log levels, context propagation, masking of sensitive data, aggregation and per-environment settings.
Does the skill require extra libraries?
It is instructions only and ships no code. It recommends a logging library with native structured output and context support such as MDC.
Source text
SKILL.md · Apache-2.0
--- name: logging-best-practices description: Logging best practices for applications and services including structured logging, log levels, and log management strategies metadata: maintainer: Mindrally source: https://github.com/Mindrally/skills --- # Logging Best Practices Apply these logging principles to ensure effective debugging, monitoring, and audit capabilities across applications and services. ## Structured Logging - Use structured logging formats (JSON) for all log output - Include consistent fields across all log entries - Make logs machine-parseable while remaining human-readable - Use a logging library that supports structured output natively - Avoid string concatenation for log messages; use structured fields ## Standard Log Fields Include these fields in every log entry: - **timestamp**: ISO 8601 format with timezone - **level**: Log severity (DEBUG, INFO, WARN, ERROR, FATAL) - **message**: Human-readable description of the event - **service**: Name of the service or application - **version**: Application version or build identifier - **trace_id**: Distributed tracing correlation ID - **span_id**: Current span identifier - **request_id**: Unique identifier for the request ## Log Levels Use appropriate log levels consistently: - **DEBUG**: Detailed diagnostic information for development - **INFO**: Normal operational events and state changes - **WARN**: Unexpected situations that are handled gracefully - **ERROR**: Failures that affect current operation but not the service - **FATAL**: Critical failures requiring immediate attention ## Context Propagation - Include request context in all log entries within a request lifecycle - Propagate trace IDs across service boundaries - Add user context (anonymized) for user-initiated actions - Include relevant business context for domain events - Use MDC (Mapped Diagnostic Context) or equivalent for context management ## Security and Privacy - Never log sensitive information (passwords, tokens, PII) - Mask or redact sensitive data when it must be referenced - Implement log access controls appropriate to data sensitivity - Consider data retention policies and compliance requirements - Audit log access for sensitive systems ## Performance Considerations - Use asynchronous logging to avoid blocking application threads - Implement log sampling for high-volume debug logs in production - Buffer logs appropriately to balance latency and throughput - Monitor logging infrastructure for bottlenecks - Set appropriate log levels per environment ## Log Aggregation - Centralize logs from all services into a single platform - Use consistent formatting across all services - Implement log rotation and retention policies - Enable full-text search and filtering capabilities - Set up log-based alerts for critical patterns ## Error Logging - Include full error context: message, code, stack trace - Log the chain of errors in wrapped/nested exceptions - Include relevant request and state information - Avoid duplicate error logging across layers - Log error recovery actions and outcomes ## Best Practices - Log at service boundaries (entry and exit points) - Include timing information for performance analysis - Log configuration changes and deployments - Create actionable log messages that aid debugging - Review and clean up logging regularly to reduce noise ## Log Message Guidelines - Write clear, descriptive messages - Include relevant identifiers (user ID, order ID, etc.) - Avoid generic messages like "Error occurred" - Use consistent terminology across the application - Include enough context to understand the event without additional lookups ## Environment-Specific Configuration - **Development**: DEBUG level, console output, verbose formatting - **Staging**: INFO level, structured JSON, full context - **Production**: INFO/WARN level, structured JSON, sampling for DEBUG
© Mindrally · Apache-2.0 · Mindrally/skills
Similar skills
Everything for Backend and APIs →logging-best-practices by other authors comes first.