home / skills / bitsoex / bitso-java / structured-logs-rfc-34

structured-logs-rfc-34 skill

/.claude/skills/structured-logs-rfc-34

This skill helps implement RFC-34 compliant structured logging in Java services, enabling consistent JSON logs with required fields and contextual data.

npx playbooks add skill bitsoex/bitso-java --skill structured-logs-rfc-34

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
3.5 KB
---
name: structured-logs-rfc-34
description: >
  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.
compatibility: Java projects using Spring Boot with Logback
metadata:
  version: "1.0.0"
  technology: java
  category: observability
  tags:
    - java
    - logging
    - rfc-34
    - structured-logs
    - observability
---

# Structured Logs (RFC-34)

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](#when-to-use-this-skill) (L24-L31)
- [Quick Start](#quick-start) (L51-L71)
- [Required Fields](#required-fields) (L72-L86)
- [Best Practices](#best-practices) (L87-L105)
- [References](#references) (L106-L111)
- [Related Rules](#related-rules) (L112-L115)
- [Related Skills](#related-skills) (L116-L121)

### Available Resources

**📚 references/** - Detailed documentation
- [logging standards](references/logging-standards.md)

---

## Quick Start

### 1. Add Dependencies

```groovy
implementation 'org.springframework.boot:spring-boot-starter-logging'
implementation 'net.logstash.logback:logstash-logback-encoder:${latest_version}'
```

### 2. Use Structured Arguments

```java
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

```java
// ✅ 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](references/logging-standards.md) | Complete RFC-34 implementation guide |

## Related Rules

- [java-structured-logs](.cursor/rules/java-structured-logs/java-structured-logs.mdc) - Full logging standards

## Related Skills

| Skill | Purpose |
|-------|---------|
| [java-standards](.claude/skills/java-standards/SKILL.md) | General Java standards |
| [java-testing](.claude/skills/java-testing/SKILL.md) | Testing log output |
<!-- AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY -->
<!-- Source: bitsoex/ai-code-instructions → java/skills/structured-logs-rfc-34/SKILL.md -->
<!-- To modify, edit the source file and run the distribution workflow -->

Overview

This skill defines RFC-34 compliant structured logging standards for Java services, focused on JSON log format, structured arguments, required fields, and Logback configuration. It guides implementation and reviews to ensure logs carry consistent service, environment, and business context. Use it to produce searchable, parseable logs that work with observability platforms.

How this skill works

The skill specifies required JSON fields (timestamp, message, logger, thread_name, level, dd.service, dd.env, dd.version) and recommends using net.logstash.logback's StructuredArguments for key/value fields. It shows the Logback encoder dependency and examples that add business identifiers as separate fields rather than embedding them in text. The guidance enforces snake_case field names and structured objects for complex data.

When to use it

  • Implement logging in a new Java service to meet RFC-34
  • Convert legacy unstructured logs to JSON structured format
  • Review or audit logging practices and compliance
  • Configure Logback to emit JSON for observability tools
  • Add business context to logs for tracing and debugging

Best practices

  • Always include required fields: @timestamp, message, logger, thread_name, level, dd.service, dd.env, dd.version
  • Prefer StructuredArguments.kv(...) to add business identifiers as separate JSON fields
  • Keep the human-readable message concise; move context into structured fields
  • Use snake_case for all field names and avoid embedding IDs in message text
  • Structure objects in JSON instead of relying on toString() representations
  • Choose log levels consistently and include enough context to interpret events

Example use cases

  • Log transaction events with transaction_id and user_id as JSON fields for traceability
  • Configure Spring Boot Logback with logstash-logback-encoder to send JSON to log aggregator
  • Audit service that requires standardized dd.service, dd.env, dd.version fields for deployment tracking
  • Refactor legacy code: replace formatted message arguments with structured kv fields
  • Create alerts and dashboards using the structured fields (level, dd.service, transaction_id) for filtering

FAQ

Which dependency adds StructuredArguments for Logback?

Use net.logstash.logback:logstash-logback-encoder and import net.logstash.logback.argument.StructuredArguments.kv for key/value fields.

What fields are mandatory for RFC-34 logs?

Required fields include @timestamp, message, logger, thread_name, level, dd.service, dd.env, and dd.version.