logging-best-practices

Emit one JSON wide-event log per request per service.

5|Updated Feb 12, 2026
One-click install
npx skills add https://github.com/agusmdev/fullstack-ai-template --skill logging-best-practices-agusmdev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/agusmdev/fullstack-ai-template/tree/main/.claude/skills/logging-best-practices
Command: npx skills add https://github.com/agusmdev/fullstack-ai-template --skill logging-best-practices-agusmdev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Wide events and canonical log lines provide consistent, context-rich logs per request to improve debugging and analytics, reducing noise from scattered log statements.

Core Features & Use Cases

  • Wide Events (CRITICAL): Emit one context-rich event per request per service, at completion, to enable end-to-end observability.
  • High Cardinality & Dimensionality (CRITICAL): Include fields such as user_id, request_id, subscription, region, and multiple context fields to support deep analytics.
  • Business Context (CRITICAL): Attach business-relevant information like subscription tier, transaction values, and feature flags.
  • Environment Characteristics (CRITICAL): Include commit hash, version, region, instance ID, and runtime info, set up at startup for all events.
  • Single Logger (HIGH): Use a single logger throughout the codebase for consistent formatting.
  • Middleware Pattern (HIGH): Use middleware to manage timing, environment, and emission.

Quick Start

Implement a single global logger and middleware to emit a JSON wide-event per request at the end of processing.

Frequently Asked Questions about logging-best-practices

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

FAQPage Schema
What are canonical log lines and how do they improve backend debugging?

Canonical log lines establish a single, JSON-formatted wide event per request per service to capture rich context. This pattern reduces noise from scattered statements and enables consistent observability, deep analytics, and easier debugging across distributed architectures.

How do I implement a wide event logging pattern in middleware?

Implement a single startup logger and use middleware to initialize, enrich, and finalize wide events. The middleware manages timing, attaches environment characteristics set at startup, adds business context during processing, and emits the JSON event at request completion.

What fields should I include in JSON wide events for high cardinality analytics?

JSON wide events should include high cardinality and dimensionality fields such as user_id, request_id, subscription, region, and multiple context fields. You also attach business context like transaction values and feature flags, plus environment characteristics like commit hash and instance ID.

Does canonical logging work for distributed architectures and microservices?

Yes, canonical logging applies this pattern across backend services and distributed architectures. By using a shared field schema across services and a single logger, it ensures consistent observability and enables end-to-end tracking for distributed systems.

Why does my service produce scattered logs instead of a single wide event per request?

Scattered logs occur without a canonical logging pattern that uses middleware to accumulate context. By establishing a single logger and middleware to manage event initialization and final emission, you replace scattered statements with one consolidated wide event per request.