Habilidades structured-logging
📋

structured-logging

Seguro 🌐 Acceso a red📁 Acceso al sistema de archivos⚙️ Comandos externos🔑 Variables de entorno

实现结构化 JSON 日志记录

También disponible en: Chemiseblanc

传统的控制台日志难以搜索和解析。本技能提供模式代码示例,用于实现 JSON 结构化日志记录,从而实现跨服务强大的过滤、聚合和可观测性。

Soporta: Claude Codex Code(CC)
📊 69 Adecuado
1

Descargar el ZIP de la skill

2

Subir en Claude

Ve a Configuración → Capacidades → Skills → Subir skill

3

Activa y empieza a usar

Pruébalo

Usando "structured-logging". 为我的 Node.js API 设置结构化日志记录

Resultado esperado:

  • 创建配置为 JSON 输出的 logger.ts
  • 添加基于环境的日志级别(生产环境为 info,开发环境为 debug)
  • 包含基础字段:服务名称、环境、requestId
  • 在开发环境使用 pino-pretty 传输以提高可读性
  • 为敏感字段配置 redact 选项

Usando "structured-logging". 如何追踪用户请求通过多个服务?

Resultado esperado:

  • 在 API 入口点使用 crypto.randomUUID() 生成唯一的 requestId
  • 通过 AsyncLocalStorage 在所有异步操作中传播 requestId
  • 在每条日志中包含 requestId 以便关联
  • 设置 x-request-id 标头用于与上游服务通信

Auditoría de seguridad

Seguro
v5 • 1/17/2026

This is a documentation-only skill containing logging best practices and code examples. All code is illustrative, demonstrating legitimate patterns like Pino/Winston configuration, AsyncLocalStorage context propagation, and sensitive data redaction. No executable code, no network calls, no credential access patterns. The static scanner flagged generic patterns in documentation examples that are false positives.

2
Archivos escaneados
632
Líneas analizadas
4
hallazgos
5
Auditorías totales

Puntuación de calidad

38
Arquitectura
100
Mantenibilidad
85
Contenido
20
Comunidad
100
Seguridad
91
Cumplimiento de la especificación

Lo que puedes crear

生产环境日志配置

使用 Pino 或 Winston 为生产服务配置结构化日志记录,以获得更好的调试和可观测性。

日志聚合管道

设置日志传输到 ELK Stack 或 Datadog,并正确传递追踪上下文。

API 请求追踪

实现请求 ID 中间件和上下文感知日志记录,以追踪跨微服务的请求。

Prueba estos prompts

基础日志器配置
设置 Pino 日志器,包含基于环境的日志级别、服务名称和开发环境美化打印模式。
上下文传播
创建 AsyncLocalStorage 上下文以在所有异步操作中传播 requestId 和 userId。
敏感数据脱敏
配置 Pino redact 选项以屏蔽密码、令牌、API 密钥和信用卡号。
日志聚合
创建 Winston 传输器,将 JSON 日志发送到 Elasticsearch 以供 ELK Stack 使用。

Mejores prácticas

  • 始终使用 ISO 8601 时间戳以确保跨系统的日志解析一致性
  • 在所有日志中包含 requestId 以实现跨服务的分布式追踪
  • 切勿记录敏感数据,如密码、令牌或信用卡号

Evitar

  • 使用字符串插值记录非结构化字符串而不是 JSON 对象
  • 在日志输出中包含敏感凭证或个人数据
  • 在生产环境中过度使用调试日志导致性能问题和日志膨胀

Preguntas frecuentes

我应该选择哪个日志记录库?
Pino 因其极低的开销和出色的性能而被推荐用于新项目。
生产环境中应该使用什么日志级别?
在生产环境中使用 info 级别以减少干扰。只有在排查问题时才启用 debug 或 trace。
如何为所有日志条目添加上下文?
使用 AsyncLocalStorage 存储 requestId 和 userId。创建一个包含上下文的包装日志器。
我的敏感数据在日志中安全吗?
使用 Pino redact 选项或自定义脱敏配置敏感字段的脱敏。
为什么我的日志没有出现在 ELK 中?
确保 JSON 格式输出,验证 Filebeat 可以解析您的格式,检查 Elasticsearch 连接性。
这与 console.log 相比如何?
结构化日志记录提供可搜索的 JSON 输出,与 console.log 不同。支持聚合和告警。

Detalles del desarrollador

Estructura de archivos

📄 SKILL.md