logging-best-practices

Implement wide-event logging with canonical log lines in web services via middleware and JSON schema.

2|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/roderik/mpe --skill logging-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/roderik/mpe/tree/main/.agents/skills/logging-best-practices
Command: npx skills add https://github.com/roderik/mpe --skill logging-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides guidelines for implementing standardized, wide-event logging to improve observability and debugging across services.

Core Features & Use Cases

  • One context-rich log per request per service (canonical log lines)
  • Automatic inclusion of environment and business context
  • Middleware-based pattern that centralizes timing, status, and emission
  • JSON-formatted logs for easy querying and analytics

Quick Start

Configure a single logger at startup, add a wide-event middleware that initializes a structured event, enrich the event in route handlers with business data, and emit the final event in a finally block.

Frequently Asked Questions about logging-best-practices

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

FAQPage Schema
What is canonical log line logging and how does it improve debugging?

Canonical log lines create a single, context-rich log per request to improve observability. By capturing environment and business context in one wide event, this logging technique makes querying and analytics significantly easier for effective debugging.

How do I implement wide-event logging in a TypeScript middleware layer?

To implement wide-event logging, configure a single startup logger, add a middleware layer to initialize the structured event, enrich it in route handlers, and emit the final event in a finally block.

Why use JSON-formatted wide events instead of multiple log lines per request?

JSON-formatted wide events centralize timing, status, and business data into one context-rich log per request. This standardized schema across services prevents fragmented logging, enabling easy querying and consistent analytics.

Does implementing canonical log lines require a specific logging framework?

Implementing canonical log lines does not require a specific framework. It requires a single startup logger and a middleware layer to initialize and emit the wide event, ensuring a consistent JSON schema across web services.

When should I use wide-event logging for web service observability?

Use wide-event logging when you need to capture a single, context-rich log per request across web services. It is ideal when automatic inclusion of environment and business context is required for effective debugging and analytics.

What are the limitations of relying on middleware for canonical logging?

Relying on middleware for canonical logging requires a consistent JSON schema across all services and proper initialization in a finally block. Limitations include ensuring business context is correctly enriched in route handlers before emission.