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

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

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

MDC.getMDCAdapter介绍

[英]Returns the MDCAdapter instance currently in use.
[中]返回当前正在使用的MDCAdapter实例。

代码示例

代码示例来源:origin: ch.qos.logback/logback-classic

public Map<String, String> getMDCPropertyMap() {
  // populate mdcPropertyMap if null
  if (mdcPropertyMap == null) {
    MDCAdapter mdc = MDC.getMDCAdapter();
    if (mdc instanceof LogbackMDCAdapter)
      mdcPropertyMap = ((LogbackMDCAdapter) mdc).getPropertyMap();
    else
      mdcPropertyMap = mdc.getCopyOfContextMap();
  }
  // mdcPropertyMap still null, use emptyMap()
  if (mdcPropertyMap == null)
    mdcPropertyMap = Collections.emptyMap();
  return mdcPropertyMap;
}

代码示例来源:origin: camunda/camunda-bpm-platform

public Map<String, String> getMDCPropertyMap() {
 // populate mdcPropertyMap if null
 if (mdcPropertyMap == null) {
  MDCAdapter mdc = MDC.getMDCAdapter();
  if (mdc instanceof LogbackMDCAdapter)
   mdcPropertyMap = ((LogbackMDCAdapter) mdc).getPropertyMap();
  else
   mdcPropertyMap = mdc.getCopyOfContextMap();
 }
 // mdcPropertyMap still null, use CACHED_NULL_MAP
 if (mdcPropertyMap == null)
  mdcPropertyMap = CACHED_NULL_MAP;
 return mdcPropertyMap;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.tools

private static void warnIfNopMDCAdapterBeingUsed() {
  try {
    MDCAdapter adapter = MDC.getMDCAdapter();
    String msg = null;
    if (adapter == null) {
      msg = "No MDC Adapter found.";
    } else if ("org.slf4j.helpers.NOPMDCAdapter".equals(adapter.getClass().getName())) {
      msg = "MDC adapter set to [org.slf4j.helpers.NOPMDCAdapter].";
    }
    if (msg != null) {
      System.err.printf("%s Possibly running with slf4j-simple. " +
          "Use Logging implementation like Logback to enable proper MDC support so " +
          "as to make use of RemoteLogDumper feature.%n", msg);
    }
  } catch (Throwable ignore) {
  }
}

代码示例来源:origin: rancher/cattle

@SuppressWarnings("unchecked")
public EventVO() {
  id = io.cattle.platform.util.resource.UUID.randomUUID().toString();
  time = new Date();
  context = MDC.getMDCAdapter().getCopyOfContextMap();
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

private void setDelegateContext() 
{
  // Logback's MDCConverter pulls in MDC properties through the slf4j's MDC class already. 
  // Therefore there's no need to bridge two MDC implementations, like in the log4j PaxLoggerImpl.
  // See PAXLOGGING-165.
  MDCAdapter adapter = MDC.getMDCAdapter();
  if (m_bundle != null && adapter != null) {
    adapter.put("bundle.id", String.valueOf(m_bundle.getBundleId()));
    adapter.put("bundle.name", m_bundle.getSymbolicName());
    adapter.put("bundle.version", m_bundle.getVersion().toString());
  }
}

代码示例来源:origin: Nextdoor/bender

public Map<String, String> getMDCPropertyMap() {
  // populate mdcPropertyMap if null
  if (mdcPropertyMap == null) {
    MDCAdapter mdc = MDC.getMDCAdapter();
    if (mdc instanceof LogbackMDCAdapter)
      mdcPropertyMap = ((LogbackMDCAdapter) mdc).getPropertyMap();
    else
      mdcPropertyMap = mdc.getCopyOfContextMap();
  }
  // mdcPropertyMap still null, use emptyMap()
  if (mdcPropertyMap == null)
    mdcPropertyMap = Collections.emptyMap();
  return mdcPropertyMap;
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

public Map<String, String> getMDCPropertyMap() {
  // populate mdcPropertyMap if null
  if (mdcPropertyMap == null) {
    MDCAdapter mdc = MDC.getMDCAdapter();
    if (mdc instanceof LogbackMDCAdapter)
      mdcPropertyMap = ((LogbackMDCAdapter) mdc).getPropertyMap();
    else
      mdcPropertyMap = mdc.getCopyOfContextMap();
  }
  // mdcPropertyMap still null, use emptyMap()
  if (mdcPropertyMap == null)
    mdcPropertyMap = Collections.emptyMap();
  return mdcPropertyMap;
}

代码示例来源:origin: tony19/logback-android

public Map<String, String> getMDCPropertyMap() {
 // populate mdcPropertyMap if null
 if (mdcPropertyMap == null) {
  MDCAdapter mdc = MDC.getMDCAdapter();
  if (mdc instanceof LogbackMDCAdapter)
   mdcPropertyMap = ((LogbackMDCAdapter) mdc).getPropertyMap();
  else
   mdcPropertyMap = mdc.getCopyOfContextMap();
 }
 // mdcPropertyMap still null, use emptyMap()
 if (mdcPropertyMap == null)
  mdcPropertyMap = Collections.emptyMap();
 return mdcPropertyMap;
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

public Map<String, String> getMDCPropertyMap() {
  // populate mdcPropertyMap if null
  if (mdcPropertyMap == null) {
    MDCAdapter mdc = MDC.getMDCAdapter();
    if (mdc instanceof LogbackMDCAdapter)
      mdcPropertyMap = ((LogbackMDCAdapter) mdc).getPropertyMap();
    else
      mdcPropertyMap = mdc.getCopyOfContextMap();
  }
  // mdcPropertyMap still null, use emptyMap()
  if (mdcPropertyMap == null)
    mdcPropertyMap = Collections.emptyMap();
  return mdcPropertyMap;
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/ch.qos.logback.classic

public Map<String, String> getMDCPropertyMap() {
 // populate mdcPropertyMap if null
 if (mdcPropertyMap == null) {
  MDCAdapter mdc = MDC.getMDCAdapter();
  if (mdc instanceof LogbackMDCAdapter)
   mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap();
  else
   mdcPropertyMap = mdc.getCopyOfContextMap();
 }
 // mdcPropertyMap still null, use CACHED_NULL_MAP
 if (mdcPropertyMap == null)
  mdcPropertyMap = CACHED_NULL_MAP;
 return mdcPropertyMap;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

private void clearDelegateContext() 
{
  MDCAdapter adapter = MDC.getMDCAdapter();
  if (m_bundle != null && adapter != null) {
    adapter.remove("bundle.id");
    adapter.remove("bundle.name");
    adapter.remove("bundle.version");
  }
  // No need to clear the underlying MDC
  // See PAXLOGGING-165.
}

代码示例来源:origin: kaazing/gateway

if (MDC.getMDCAdapter() instanceof BasicMDCAdapter) {
  BasicMDCAdapter mdcAdapter = (BasicMDCAdapter) MDC.getMDCAdapter();
  Set keySet = mdcAdapter.getKeys();
  if (keySet != null && keySet.size() > 0) {

代码示例来源:origin: net.kencochrane.raven/raven

Map<String, String> mdc = MDC.getMDCAdapter().getCopyOfContextMap();
if (mdc != null) {
  for (Map.Entry<String, String> mdcEntry : mdc.entrySet()) {

代码示例来源:origin: com.getsentry.raven/raven

Map<String, String> mdc = MDC.getMDCAdapter().getCopyOfContextMap();
if (mdc != null) {
  for (Map.Entry<String, String> mdcEntry : mdc.entrySet()) {

代码示例来源:origin: io.sentry/sentry

Map<String, String> mdc = MDC.getMDCAdapter().getCopyOfContextMap();
if (mdc != null) {
  for (Map.Entry<String, String> mdcEntry : mdc.entrySet()) {

代码示例来源:origin: com.alibaba.citrus.tool/antx-autoexpand

public LoggingEvent(String fqcn, Logger logger, Level level, String message,
  Throwable throwable, Object[] argArray) {
 this.fqnOfLoggerClass = fqcn;
 this.loggerName = logger.getName();
 this.loggerContext = logger.getLoggerContext();
 this.loggerContextVO = loggerContext.getLoggerContextRemoteView();
 this.level = level;
 this.message = message;
 if (throwable != null) {
  this.throwableProxy = new ThrowableProxy(throwable);
  LoggerContext lc = logger.getLoggerContext();
  if (lc.isPackagingDataEnabled()) {
   this.throwableProxy.calculatePackagingData();
  }
 }
 // bug 85 (we previously failed to set this.argumentArray)
 this.argumentArray = argArray;
 timeStamp = System.currentTimeMillis();
 // the case is ugly but under the circumstances acceptable
 LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC
   .getMDCAdapter();
 mdcPropertyMap = logbackMDCAdapter.getPropertyMap();
}

相关文章