org.slf4j.MDC.setContextMap()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中org.slf4j.MDC.setContextMap()方法的一些代码示例,展示了MDC.setContextMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MDC.setContextMap()方法的具体详情如下:
包路径:org.slf4j.MDC
类名称:MDC
方法名:setContextMap

MDC.setContextMap介绍

[英]Set the current thread's context map by first clearing any existing map and then copying the map passed as parameter. The context map passed as parameter must only contain keys and values of type String.
[中]通过首先清除任何现有映射,然后复制作为参数传递的映射,设置当前线程的上下文映射。作为参数传递的上下文映射只能包含字符串类型的键和值。

代码示例

代码示例来源:origin: debezium/debezium

/**
   * Restore this logging context.
   */
  public void restore() {
    MDC.setContextMap(context);
  }
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 public void run() {
  Map<String, String> originalContext = MDC.getCopyOfContextMap();
  if (context != null) {
   MDC.setContextMap(context);
  }
  try {
   this.runnable.run();
  } finally {
   if (originalContext != null) {
    MDC.setContextMap(originalContext);
   } else {
    MDC.clear();
   }
  }
 }
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 public T call() throws Exception {
  T answer;
  Map<String, String> originalContext = MDC.getCopyOfContextMap();
  if (context != null) {
   MDC.setContextMap(context);
  }

  try {
   answer = this.callable.call();
  } finally {
   if (originalContext != null) {
    MDC.setContextMap(originalContext);
   } else {
    MDC.clear();
   }
  }

  return answer;
 }
}

代码示例来源:origin: apache/incubator-gobblin

Map<String, String> originalContext = MDC.getCopyOfContextMap();
if (this.mdcContext != null) {
 MDC.setContextMap(this.mdcContext);
} finally {
 if (originalContext != null) {
  MDC.setContextMap(originalContext);
 } else {
  MDC.clear();

代码示例来源:origin: apache/incubator-druid

if (setMDC) {
 if (mdc != null) {
  MDC.setContextMap(mdc);
 } else {
  MDC.clear();

代码示例来源:origin: webx/citrus

/** 将map中的值设置到MDC中。 */
protected void setMDC(Map<String, String> mdc) {
  MDC.setContextMap(mdc);
}

代码示例来源:origin: webx/citrus

/** 将map中的值设置到MDC中。 */
protected void setMDC(Map<String, String> mdc) {
  MDC.setContextMap(mdc);
}

代码示例来源:origin: rhwayfun/spring-boot-learning-examples

@Override
  public void run() {
    try {
      MDC.setContextMap(map);
      wrapped.run();
    } finally {
      MDC.clear();
    }
  }
}

代码示例来源:origin: ebean-orm/ebean

@Override
public V call() throws Exception {
 MDC.setContextMap(map);
 try {
  return c.call();
 } finally {
  MDC.clear();
 }
}

代码示例来源:origin: rhwayfun/spring-boot-learning-examples

@Override
  public void run() {
    Map<String, String> previous = MDC.getCopyOfContextMap();
    if (context == null) {
      MDC.clear();
    } else {
      MDC.setContextMap(context);
    }
    try {
      runnable.run();
    } finally {
      if (previous == null) {
        MDC.clear();
      } else {
        MDC.setContextMap(previous);
      }
    }
  }
};

代码示例来源:origin: rhwayfun/spring-boot-learning-examples

@Override
  public void run() {
    Map<String, String> previous = MDC.getCopyOfContextMap();
    if (contextMap == null) {
      MDC.clear();
    } else {
      MDC.setContextMap(contextMap);
    }
    try {
      //调用run方法不会在主线程执行
      runnable.run();
    } finally {
      if (previous == null) {
        MDC.clear();
      } else {
        MDC.setContextMap(previous);
      }
    }
  }
};

代码示例来源:origin: ebean-orm/ebean

@Override
public ScheduledFuture<?> schedule(Runnable r, long delay, TimeUnit unit) {
 final Map<String, String> map = MDC.getCopyOfContextMap();
 if (map == null) {
  return schedulePool.schedule(r, delay, unit);
 } else {
  return schedulePool.schedule(() -> {
   MDC.setContextMap(map);
   try {
    r.run();
   } finally {
    MDC.clear();
   }
  }, delay, unit);
 }
}

代码示例来源:origin: ebean-orm/ebean

@Override
public void executePeriodically(Runnable r, long delay, TimeUnit unit) {
 final Map<String, String> map = MDC.getCopyOfContextMap();
 if (map == null) {
  schedulePool.scheduleWithFixedDelay(r, delay, delay, unit);
 } else {
  schedulePool.scheduleWithFixedDelay(() -> {
   MDC.setContextMap(map);
   try {
    r.run();
   } finally {
    MDC.clear();
   }
  }, delay, delay, unit);
 }
}

代码示例来源:origin: DV8FromTheWorld/JDA

MDC.setContextMap(contextMap);
long lastFrameSent = System.currentTimeMillis();
boolean sentPacket = true;

代码示例来源:origin: ebean-orm/ebean

/**
 * Execute a Runnable using a background thread.
 */
@Override
public void execute(Runnable r) {
 final Map<String, String> map = MDC.getCopyOfContextMap();
 if (map == null) {
  pool.execute(r);
 } else {
  pool.execute(() -> {
   MDC.setContextMap(map);
   try {
    r.run();
   } finally {
    MDC.clear();
   }
  });
 }
}

代码示例来源:origin: org.apache.solr/solr-solrj

public void logDebugWithMdc(Logger logger, String msg) {
 Map previousMdcContext = MDC.getCopyOfContextMap();
 MDC.setContextMap(mdcContext);
 try {
  logger.debug(msg);
 } finally{
  MDC.setContextMap(previousMdcContext);
 }
}

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

@Override
  public T call() throws Exception {
    try {
      MDC.setContextMap(contextMap);
      return delegate.call();
    } finally {
      MDC.clear();
    }
  }
}

代码示例来源:origin: zeroturnaround/zt-exec

public T call() throws Exception {
 MDC.setContextMap(contextMap);
 try {
  return target.call();
 }
 finally {
  MDC.clear();
 }
}

代码示例来源:origin: zeroturnaround/zt-exec

public void run() {
 MDC.setContextMap(contextMap);
 try {
  target.run();
 }
 finally {
  MDC.clear();
 }
}

代码示例来源:origin: OpenNMS/opennms

public static void setContextMap(final Map<String, String> mdc) {
  if (mdc == null) {
    MDC.clear();
  } else {
    MDC.setContextMap(mdc);
  }
}

相关文章