logging-best-practices

Implement standardized JSON wide events for each request via configurable middleware.

Updated Jan 27, 2026
One-click install
npx skills add https://github.com/Loosand/next-forge --skill logging-best-practices-loosand
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: logging-best-practices
Source: https://github.com/Loosand/next-forge/tree/main/.agents/skills/logging-best-practices
Command: npx skills add https://github.com/Loosand/next-forge --skill logging-best-practices-loosand

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

通过统一的宽事件日志策略,提升跨服务的可观测性、可检索性与调试效率。

Core Features & Use Cases

  • 宽事件作为单一、上下文丰富的日志事件,覆盖请求全生命周期
  • 包含高基数与高维度字段(用户、订阅、请求ID、环境信息等)
  • 环境特征字段在每个事件中自动注入,便于定位问题版本与部署
  • 中间件模式实现一致性,简化跨服务日志采集
  • 输出为 JSON 单行,便于查询与分析

Quick Start

Add a single, centralized wide-event middleware to your app and ensure each request emits one structured JSON wide event.

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

Canonical log lines are single, context-rich wide events emitted per request to improve debugging. They capture high-cardinality fields, business context, and environmental data in JSON format for end-to-end traceability and reliable analytics.

How do I implement structured logging across multiple services?

Implement structured logging across services by applying a single, centralized middleware to assemble and emit one JSON wide event per request. This ensures consistent capture of high-cardinality fields and environmental data for simplified cross-service log collection.

How does middleware help capture environmental data in structured logs?

Middleware automatically injects environmental characteristics into every structured log event. This ensures each JSON wide event contains deployment and version metadata, allowing you to quickly locate problematic versions during debugging.

What is the best way to format application logs for fast search and analytics?

The best way to format application logs for analytics is emitting single-line JSON wide events. This structured logging approach captures request lifecycle context and high-dimensional fields, enabling fast querying and reliable end-to-end traceability.

Can I use a single logger configuration for all request lifecycle logs?

Yes, you can use a single, configurable logger with middleware to handle all request lifecycle logs. This setup ensures each request emits exactly one structured JSON wide event, maintaining consistency and preventing fragmented logging.

Why should I use wide events instead of traditional logging?

Wide events provide a single, context-rich log event covering the entire request lifecycle, unlike traditional logging. They encapsulate high-cardinality and business context fields in one JSON line, enabling fast debugging and reliable analytics without fragmented log entries.