structured-logging
RFC-34 compliant structured logging standards for Java services. Covers JSON log format, structured arguments, required fields, and Logback configuration. Use when implementing or reviewing logging in Java services.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Structured Logging
RFC-34 compliant structured logging standards for Java services.
When to use this skill
- Implementing logging in new Java services
- Converting unstructured logs to structured format
- Reviewing logging practices
- Configuring Logback for JSON output
- Adding business context to logs
Skill Contents
Sections
- When to use this skill (L24-L31)
- Quick Start (L51-L71)
- Required Fields (L72-L86)
- Best Practices (L87-L105)
- References (L106-L111)
- Related Rules (L112-L115)
- Related Skills (L116-L121)
Available Resources
📚 references/ - Detailed documentation
Quick Start
1. Add Dependencies
implementation 'org.springframework.boot:spring-boot-starter-logging'
implementation 'net.logstash.logback:logstash-logback-encoder:${latest_version}'
2. Use Structured Arguments
import static net.logstash.logback.argument.StructuredArguments.kv;
log.info("Transaction processed",
kv("transaction_id", txn.getId()),
kv("user_id", user.getId()));
This produces JSON with separate fields for transaction_id and user_id.
Required Fields
All logs must include these fields:
| Field | Description |
|---|---|
@timestamp |
Log timestamp |
message |
Log message text |
logger |
Logger name |
thread_name |
Thread name |
level |
Log level (INFO, WARN, ERROR, etc.) |
dd.service |
Service name |
dd.env |
Environment |
dd.version |
Service version |
Best Practices
- Add business identifiers (IDs) as separate fields instead of embedding in messages
- Keep log message text clear and concise
- Use appropriate log levels consistently
- Include enough context to understand the event without additional queries
- Use snake_case for field names
- For logs containing objects, properly structure them rather than using
toString()
Example
// ✅ Good - structured fields
log.info("Order created", kv("order_id", orderId), kv("user_id", userId), kv("amount", amount));
// ❌ Bad - embedded in message
log.info("Order {} created for user {} with amount {}", orderId, userId, amount);
References
| Reference | Description |
|---|---|
| references/logging-standards.md | Complete RFC-34 implementation guide |
Related Rules
-
.cursor/rules/java-structured-logs.mdc- Full logging standards
Related Skills
| Skill | Purpose |
|---|---|
| java-standards | General Java standards |
| java-testing | Testing log output |
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-28
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!