Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill logging-best-practices -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/logging-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/logging-best-practices/

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.

logging-best-practices boristane This skill guides your agent to implement wide events (canonical log lines) instead of scattered logs. It consolidates request metrics, business context, and errors into one JSON event. CX Codex +1 4,800installs logging-best-practices aj-geddes A skill for setting up logging: levels, JSON output, context fields, PII handling and centralized collection. CX Codex +1 730installs logging-best-practices secondsky A skill that tells your agent how to log: levels, request context, PII masking. Useful when logs bloat or passwords end up in them. CX Codex +1 396installs go-logging cxuu A skill that steers your coding agent toward sane Go logging: slog, levels, structured fields, request-scoped context. Useful once a Go service grows more log lines than anyone reads. CX Codex +1 1,000installs logging codewithmukesh A .NET 10 observability skill: splits liveness from readiness, wires correlation IDs, and sets log levels. CX Codex +1 2,800installs review-logging-patterns HugoRCD The skill audits logging in a TypeScript codebase, flags console.log spam and context-free errors, and suggests moving to evlog. CX Codex +1 750installs sentry-instrument-logging getsentry Adds structured Sentry logs to an app: the agent inventories your repo and writes log messages that follow shared conventions. CX Codex +1 533installs serilog codewithmukesh This skill guides an agent through Serilog structured logging in .NET 10 apps, including bootstrap logging, sinks, event properties, and HTTP request logs. CX Codex +1 2,900installs application-logging aj-geddes A skill that walks your agent through structured logging: levels, context, request tracing and centralized aggregation. CX Codex +1 496installs

From the same set168

web-development A skill that hands the agent web development conventions: Bootstrap grid, Django views and models, HTMX attributes. Useful when templates and backend live in one repo. CX Codex +1 815installs blazor A skill that gives your coding agent Blazor rules: component lifecycle, data binding, state management and render optimization. CX Codex +1 798installs ionic Gives the agent a set of Ionic rules: feature-based structure, built-in components, SCSS theming, lazy loading and Firebase. CX Codex +1 797installs general-best-practices A skill that hands your coding agent a set of rules on code quality, testing, security and architecture. Useful when you want consistent code across a project. CX Codex +1 794installs python-odoo-cursor-rules A rule set for Python and Odoo development: ORM, XML views, module architecture. Useful when the agent writes ERP code. CX Codex +1 790installs android-development A rule set that keeps your coding agent on track with Kotlin and Android: clean architecture, MVI, Material 3. Useful when generated code drifts in style and layering. CX Codex +1 782installs kysely A skill that gives the agent rules for writing Kysely code: schema typing, joins, transactions, type generation. Useful when your project is TypeScript and SQL. CX Codex +1 780installs github-workflow A rule set that tells your agent how to work with GitHub: pull requests, review comments, Actions workflows, issue templates and branch protection. Useful whenever the agent touches a repo. CX Codex +1 780installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor