logging-best-practices

Implements structured JSON logging with correlation IDs for production systems.

Updated Sep 6, 2026
One-click install
npx skills add https://github.com/inventashif/helpful-code-sidekick --skill logging-best-practices-inventashif
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/inventashif/helpful-code-sidekick/tree/main/scripts/hackerai/.agents/skills/logging-best-practices
Command: npx skills add https://github.com/inventashif/helpful-code-sidekick --skill logging-best-practices-inventashif

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Production logs are often unstructured, missing context, and impossible to query during incidents, leaving engineers unable to answer who was affected, what failed, and why within minutes. ## Core Features & Use Cases - Structured Logging Standards: Enforces JSON key-value log events with required fields like timestamp, level, event, request_id, service, and environment. - Context Propagation: Guides passing trace and request IDs across service boundaries, message queues, and async jobs for end-to-end correlation. - Log Level & Content Discipline: Defines correct use of debug, info, warn, and error levels plus rules for what to log and what to exclude, such as passwords, tokens, and PII. - Use Case: When adding logging to a payment service, apply these rules to emit events like {"event": "payment_failed", "user_id": "123", "reason": "insufficient_funds"} so on-call engineers can filter and trace failures instantly. ## Quick Start Review the logging in my service and rewrite it to follow structured logging best practices with correlation IDs.

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 in a production system?

Structured logging uses JSON key-value pairs instead of string interpolation, for example {"event": "payment_failed", "user_id": "123"}. Every event should include timestamp, level, event name, request_id, service, and environment so logs are machine-parseable and queryable.

What fields should every log event include?

Every log event should include an ISO 8601 timestamp, a level (debug, info, warn, error), a snake_case event name, a request_id or trace_id, the service name, and the environment. High-cardinality fields like user_id, org_id, and order_id make logs queryable during incidents.

How do I propagate trace IDs across microservices?

Pass trace and request IDs through all service boundaries using HTTP headers or message queue metadata, and have downstream services inherit them. Use middleware or interceptors to inject context automatically, and store and restore the original request context for async jobs.

What should not be logged in production applications?

Never log sensitive data such as passwords, tokens, PII, or credit card numbers. Also avoid logging inside tight loops, success cases with no debugging value, and information already captured by infrastructure like load balancer logs.

When should I use warn versus error log levels?

Use warn when something unexpected happened but the system handled it, such as retries or fallbacks. Use error when something failed and likely needs human attention, such as exceptions or failed requests, and avoid logging errors for expected conditions like a wrong password.