Interface MDCAdapter
public interface MDCAdapter
MDC Adapter Interface - Mapped Diagnostic Context Adapter
MDC 适配器接口 - 映射诊断上下文适配器
This interface provides an abstraction layer for MDC operations, allowing different logging frameworks to provide their own implementations.
此接口为 MDC 操作提供抽象层,允许不同的日志框架提供自己的实现。
Features | 主要功能:
- Key-value context storage abstraction - 键值上下文存储抽象
- Context map copy and restore operations - 上下文映射拷贝和恢复操作
- Thread-isolated diagnostic context - 线程隔离的诊断上下文
Usage Examples | 使用示例:
// Implement custom MDC adapter
public class MyMDCAdapter implements MDCAdapter {
@Override
public void put(String key, String value) { ... }
@Override
public String get(String key) { ... }
// ... other methods
}
Security | 安全性:
- Thread-safe: Implementation-dependent - 线程安全: 取决于实现
- Null-safe: Yes (returns null for missing keys) - 空值安全: 是(缺少的键返回 null)
- Since:
- JDK 25, opencode-base-log V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all entries from the MDC.Gets a value from the MDC.Returns a copy of the current context map.voidPuts a key-value pair into the MDC.voidRemoves a key from the MDC.voidsetContextMap(Map<String, String> contextMap) Sets the context map.
-
Method Details
-
put
-
get
-
remove
Removes a key from the MDC. 从 MDC 移除键。- Parameters:
key- the key to remove - 要移除的键
-
clear
void clear()Clears all entries from the MDC. 清空 MDC 中的所有条目。 -
getCopyOfContextMap
-
setContextMap
-