logging-best-practices

Implement wide-event JSON logging with environment enrichment via middleware.

2|Updated Aug 1, 2024
One-click install
npx skills add https://github.com/Kabilan108/dotfiles --skill logging-best-practices-kabilan108
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/Kabilan108/dotfiles/tree/main/agents/skills/logging-best-practices
Command: npx skills add https://github.com/Kabilan108/dotfiles --skill logging-best-practices-kabilan108

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides guidelines for implementing comprehensive, wide-event logging across services. It helps teams create context-rich, structured log lines that enable fast debugging, analytics, and observability.

Core Features & Use Cases

  • Wide events pattern: emit a single, context-rich event per request per service to replace scattered logs and improve queryability.
  • High cardinality & dimensionality: includes user, request, session, and business context to support powerful filtering and analysis.
  • Environment and consistency: middleware automatically enriches logs with environment data (version, region, deploy id) and enforces a single JSON schema.
  • Use cases: debugging distributed failures, monitoring service health, and correlating events across microservices.

Quick Start

Install a single JSON logger at startup, implement a middleware to collect and emit wide events, and wrap handlers to enrich with business context. Ensure environment context is captured once and included in every event. Start producing queryable, structured logs for rapid debugging.

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 microservice debugging?

Canonical log lines are single, context-rich JSON events emitted per request per service. They replace scattered logs with high-cardinality data, enabling fast debugging and powerful filtering across distributed microservice architectures.

How do I implement wide-event logging in a backend API?

Install a JSON logger at startup, implement middleware to collect and emit wide events, and wrap handlers to enrich them with business context. Capture environment data once to ensure a consistent schema across all emitted events.

Does wide-event logging require a specific framework or platform?

Wide-event logging applies to any backend service, API, or microservice architecture. It requires no specific platform, relying instead on middleware to enforce a single JSON schema and capture environment-aware context.

What is the best way to structure JSON logs for observability and analytics?

The best way is using the wide events pattern to include user, request, session, and business context. Middleware automatically enriches these JSON logs with environment data like version and region for consistent queryability.

How does middleware enrich logs with environment and business context?

Middleware automatically captures environment data such as version, region, and deploy ID at startup. It then wraps handlers to append high-cardinality business context, emitting a single JSON-formatted event per request.

How do I distinguish between info and error events in a canonical log line?

Canonical log lines support distinguishing info and error events within the single JSON logger schema. This separation maintains consistent queryability while allowing teams to filter specific event types during analysis.