org.slf4j.spi.MDCAdapter.put()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(15.2k)|赞(0)|评价(0)|浏览(222)

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

MDCAdapter.put介绍

[英]Put a context value (the val parameter) as identified with the key parameter into the current thread's context map. The key parameter cannot be null. The val parameter can be null only if the underlying implementation supports it.

If the current thread does not have a context map it is created as a side effect of this call.
[中]将用key参数标识的上下文值(val参数)放入当前线程的上下文映射中。key参数不能为空。val参数只能在底层实现支持的情况下为空。
如果当前线程没有上下文映射,则会将其创建为该调用的副作用。

代码示例

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

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

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

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

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

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val)
  throws IllegalArgumentException {
 if (key == null) {
  throw new IllegalArgumentException("key parameter cannot be null");
 }
 if (mdcAdapter == null) {
  throw new IllegalStateException("MDCAdapter cannot be null. See also "
    + NULL_MDCA_URL);
 }
 mdcAdapter.put(key, val);
}

代码示例来源:origin: org.echocat.jomon/runtime

@Override
public void put(String key, String val) {
  _delegate.put(key, val != null ? val : "");
}

代码示例来源:origin: brant-hwang/spring-logback-slack-notification-example

public static void set(String key, String value) {
  mdc.put(key, value);
}

代码示例来源: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: com.alibaba.citrus.tool/antx-autoexpand

/**
 * Put a context value (the <code>val</code> parameter) as identified with
 * the <code>key</code> parameter into the current thread's context map.
 * The <code>key</code> parameter cannot be null. The <code>val</code> parameter 
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 * 
 * @throws IllegalArgumentException in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
 if (key == null) {
  throw new IllegalArgumentException("key parameter cannot be null");
 }
 if (mdcAdapter == null) {
  throw new IllegalStateException("MDCAdapter cannot be null. See also "
    + NULL_MDCA_URL);
 }
 mdcAdapter.put(key, val);
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

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

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

代码示例来源:origin: org.apache.activemq/activemq-all

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

代码示例来源:origin: org.apache.directory.api/api-ldap-client-all

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

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

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

代码示例来源:origin: wolpi/prim-ftpd

/**
 * Put a context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val)
  throws IllegalArgumentException {
 if (key == null) {
  throw new IllegalArgumentException("key parameter cannot be null");
 }
 if (mdcAdapter == null) {
  throw new IllegalStateException("MDCAdapter cannot be null. See also "
    + NULL_MDCA_URL);
 }
 mdcAdapter.put(key, val);
}

代码示例来源:origin: com.github.oshi/oshi-core-shaded

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

代码示例来源:origin: uk.co.nichesolutions/slf4j-api

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

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

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

代码示例来源:origin: brant-hwang/spring-logback-slack-notification-example

public static void setJsonValue(String key, Object value) {
  try {
    if (value != null) {
      String json = JsonUtils.toJson(value);
      mdc.put(key, json);
    }
  } catch (Exception e) {
    // ignored
  }
}

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

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val) throws IllegalArgumentException {
  if (key == null) {
    throw new IllegalArgumentException("key parameter cannot be null");
  }
  if (mdcAdapter == null) {
    throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
  }
  mdcAdapter.put(key, val);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.slf4j.api

/**
 * Put a diagnostic context value (the <code>val</code> parameter) as identified with the
 * <code>key</code> parameter into the current thread's diagnostic context map. The
 * <code>key</code> parameter cannot be null. The <code>val</code> parameter
 * can be null only if the underlying implementation supports it.
 * 
 * <p>
 * This method delegates all work to the MDC of the underlying logging system.
 *
 * @param key non-null key 
 * @param val value to put in the map
 * 
 * @throws IllegalArgumentException
 *           in case the "key" parameter is null
 */
public static void put(String key, String val)
  throws IllegalArgumentException {
 if (key == null) {
  throw new IllegalArgumentException("key parameter cannot be null");
 }
 if (mdcAdapter == null) {
  throw new IllegalStateException("MDCAdapter cannot be null. See also "
    + NULL_MDCA_URL);
 }
 mdcAdapter.put(key, val);
}

相关文章