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 Details

    • put

      void put(String key, String value)
      Puts a key-value pair into the MDC. 将键值对放入 MDC。
      Parameters:
      key - the key - 键
      value - the value - 值
    • get

      String get(String key)
      Gets a value from the MDC. 从 MDC 获取值。
      Parameters:
      key - the key - 键
      Returns:
      the value, or null if not found - 值,如果未找到则返回 null
    • remove

      void remove(String key)
      Removes a key from the MDC. 从 MDC 移除键。
      Parameters:
      key - the key to remove - 要移除的键
    • clear

      void clear()
      Clears all entries from the MDC. 清空 MDC 中的所有条目。
    • getCopyOfContextMap

      Map<String,String> getCopyOfContextMap()
      Returns a copy of the current context map. 返回当前上下文映射的副本。
      Returns:
      a copy of the context map - 上下文映射的副本
    • setContextMap

      void setContextMap(Map<String,String> contextMap)
      Sets the context map. 设置上下文映射。
      Parameters:
      contextMap - the context map - 上下文映射