logging-best-practices

Enforce wide-event JSON logging with middleware and consistent schemas.

4|Updated Jan 8, 2026
One-click install
npx skills add https://github.com/allthingslinux/portal --skill logging-best-practices-allthingslinux
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/allthingslinux/portal/tree/main/.cursor/skills/logging-best-practices
Command: npx skills add https://github.com/allthingslinux/portal --skill logging-best-practices-allthingslinux

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Logging best practices focused on wide events (canonical log lines) for powerful debugging and analytics

Core Features & Use Cases

  • Single wide event per request: Emit a single, context-rich JSON log per service at request completion for reliable traceability.
  • Middleware-driven collection: Use a middleware wrapper to assemble timing, environment, and outcomes, then emit once.
  • Consistent schema: Enforce uniform field layout across services to simplify querying, alerting, and analytics.
  • Use Case: When debugging a multi-service failure, correlate logs across services via a shared requestId and a rich, searchable event.

Quick Start

Enable the wide-event middleware, initialize a single logger, and annotate handlers with business context before emitting the event.

Frequently Asked Questions about logging-best-practices

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

FAQPage Schema
What is wide-event structured logging and when do I need it for my backend services?

Wide-event structured logging emits a single context-rich JSON log per request to improve debugging and observability. You need it for backend services, APIs, and microservices that rely on consistent logs for incident analysis, performance monitoring, and business insight.

How do I implement canonical log lines using middleware in TypeScript?

Implement canonical log lines by enabling a middleware wrapper that assembles timing, environment, and outcomes, then emits a single JSON log at request completion. Initialize one logger and annotate handlers with business context before emitting the event.

Can I correlate logs across microservices for debugging a multi-service failure?

Yes, you can correlate logs across microservices by including a shared requestId and environment context in a consistent JSON schema. This allows you to trace a single request through multiple services via one searchable, wide-event log entry.

What's the best way to enforce consistent JSON logging schemas across multiple APIs?

The best way to enforce consistent JSON logging schemas is to use a single logger and a middleware-driven collection process. This ensures a uniform field layout across services, simplifying querying, alerting, and analytics for all your APIs.

Do I need a specific logging library to use wide-event logging in my microservices?

No specific logging library is required, but you must use a single logger instance across your service. The focus is on the architectural pattern: middleware-driven collection that emits one structured JSON event per request with consistent fields and correlation IDs.

Why does my structured logging schema break when querying across different backend services?

Structured logging schemas break across services when there is no enforced uniform field layout. Applying a middleware wrapper to assemble a consistent JSON schema with shared request correlation ensures reliable querying and analytics across all backend services.