logging-best-practices

Define structured logging and correlation ID practices for distributed production services.

12|Updated Dec 23, 2025
One-click install
npx skills add https://github.com/nbbaier/agent-skills --skill logging-best-practices-nbbaier
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/nbbaier/agent-skills/tree/main/skills/logging-best-practices
Command: npx skills add https://github.com/nbbaier/agent-skills --skill logging-best-practices-nbbaier

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

In large production environments, inconsistent logging makes debugging, incident response, and cross-service analysis slow and error-prone.

Core Features & Use Cases

  • Structured logging: use JSON key-value pairs to enable machine parsing and centralized querying.
  • Context propagation: automatically thread trace_id and span_id through service boundaries for end-to-end visibility.
  • Log level discipline: use debug, info, warn, and error appropriately to balance verbosity and signal.
  • Field discipline: enforce required fields such as timestamp, level, event, request_id, service, and environment.
  • Naming and data hygiene: maintain consistent field names, avoid sensitive data, and minimize PII exposure.
  • Incident-ready logging: provide insights into state transitions, latency, and external calls for post-mortems.

Quick Start

Configure your services to emit structured logs with correlation IDs across all environments to enable efficient incident response.

Frequently Asked Questions about logging-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement structured logging for distributed services?

Implement structured logging by emitting JSON key-value pairs to enable machine parsing and centralized querying across distributed services. This approach enforces required fields like timestamp, level, event, and request_id for consistent cross-service analysis.

What is a correlation ID and how does it improve incident triage?

A correlation ID, such as trace_id or span_id, is a unique identifier threaded through service boundaries to provide end-to-end visibility. Context propagation of these IDs allows you to track requests across distributed services for faster incident triage.

What are the best practices for log level discipline in production systems?

Log level discipline requires using debug, info, warn, and error appropriately to balance verbosity and signal. Maintaining this discipline ensures production logs remain useful for incident response without generating excessive noise.

How do I maintain data hygiene and avoid PII exposure in application logs?

Maintain data hygiene by enforcing consistent field names, avoiding sensitive data, and minimizing PII exposure in your logs. This practice ensures safe data handling across all environments while preserving the context needed for debugging.

Does this logging guidance apply to medium-to-large production environments?

Yes, this logging guidance specifically applies to medium-to-large production environments with distributed services. It targets systems that require structured logs, correlation IDs, and safe data handling to improve observability and incident response.

What required fields should I include in structured logs for incident management?

Required fields for incident-ready structured logs include timestamp, level, event, request_id, service, and environment. These fields provide insights into state transitions, latency, and external calls necessary for effective post-mortems.