Logging Best Practices

Implement structured JSON logging with essential fields and context propagation.

1|Updated Mar 30, 2022
One-click install
npx skills add https://github.com/fcoury/config --skill logging-best-practices-fcoury
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Logging Best Practices
Source: https://github.com/fcoury/config/tree/main/ai/skills/logs
Command: npx skills add https://github.com/fcoury/config --skill logging-best-practices-fcoury

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a comprehensive guide to implementing effective logging strategies in medium to large-scale production systems, ensuring logs are optimized for querying and debugging.

Core Features & Use Cases

  • Structured Logging: Enforces the use of key-value pairs (JSON) for machine-parseable logs.
  • Required Fields: Defines essential fields like timestamp, level, event, request_id, service, and environment for every log event.
  • Context Propagation: Details how to maintain correlation IDs across distributed systems.
  • Use Case: Implement these guidelines to ensure your system's logs are easily searchable and actionable during critical incidents, allowing for rapid root cause analysis.

Quick Start

Follow these principles to implement structured logging in your production system.

Frequently Asked Questions about Logging Best Practices

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

FAQPage Schema
What is structured logging and why do I need it for production systems?

Structured logging uses key-value pairs like JSON to make logs machine-parseable. It is needed in production systems to optimize querying and debugging, ensuring logs are actionable during critical incidents for rapid root cause analysis.

How do I implement structured logging for debugging and incident response?

To implement structured logging for debugging, use JSON formats and include essential fields like timestamp, level, event, request_id, service, and environment. This ensures logs are easily searchable and actionable during incident response.

What essential fields should I include in structured logs for distributed systems?

Essential fields for structured logs include timestamp, level, event, request_id, service, and environment. For distributed systems, you must also propagate context using correlation IDs to maintain traceability across services.

What's the best way to manage log levels and context propagation in production?

The best way to manage log levels and context propagation is to follow strict naming conventions and propagate correlation IDs across distributed services. This optimizes query performance and maintains context for incident response.

What should I not log in production to avoid performance issues?

To avoid performance issues in production, you should not log excessive or unnecessary data. Follow specific guidelines on what to log versus what not to log, and consider performance implications when designing your logging strategy.