Class StructuredLog
java.lang.Object
cloud.opencode.base.log.enhance.StructuredLog
Structured Log - JSON-style Structured Logging
结构化日志 - JSON 风格的结构化日志
StructuredLog provides a fluent API for creating structured log entries with key-value pairs, suitable for log aggregation systems like ELK/Loki.
StructuredLog 提供流式 API 来创建带键值对的结构化日志条目, 适合 ELK/Loki 等日志聚合系统。
Example | 示例:
StructuredLog.info()
.message("User login successful")
.field("userId", "user123")
.field("ip", "192.168.1.1")
.field("duration", 150)
.log();
// Output (JSON format):
// {"message":"User login successful","userId":"user123","ip":"192.168.1.1","duration":150}
Features | 主要功能:
- Fluent builder API for structured log entries - 用于结构化日志条目的流式构建器 API
- JSON-format output for log aggregation systems - JSON 格式输出,适用于日志聚合系统
- Support for all log levels, markers, and exceptions - 支持所有日志级别、标记和异常
- Automatic JSON escaping of special characters - 自动 JSON 转义特殊字符
Security | 安全性:
- Thread-safe: No (Builder is not shared) - 线程安全: 否(Builder 不共享)
- Null-safe: Yes (null fields are skipped) - 空值安全: 是(null 字段被跳过)
- Since:
- JDK 25, opencode-base-log V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classStructured Log Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic StructuredLog.Builderdebug()Creates a DEBUG level structured log builder.static StructuredLog.Buildererror()Creates an ERROR level structured log builder.static StructuredLog.Builderinfo()Creates an INFO level structured log builder.static StructuredLog.Buildertrace()Creates a TRACE level structured log builder.static StructuredLog.Builderwarn()Creates a WARN level structured log builder.
-
Method Details
-
trace
Creates a TRACE level structured log builder. 创建 TRACE 级别的结构化日志构建器。- Returns:
- the builder - 构建器
-
debug
Creates a DEBUG level structured log builder. 创建 DEBUG 级别的结构化日志构建器。- Returns:
- the builder - 构建器
-
info
Creates an INFO level structured log builder. 创建 INFO 级别的结构化日志构建器。- Returns:
- the builder - 构建器
-
warn
Creates a WARN level structured log builder. 创建 WARN 级别的结构化日志构建器。- Returns:
- the builder - 构建器
-
error
Creates an ERROR level structured log builder. 创建 ERROR 级别的结构化日志构建器。- Returns:
- the builder - 构建器
-