org.apache.log4j.MDC.get()方法的使用及代码示例

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

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

MDC.get介绍

[英]Get the context identified by the key parameter.

This method has no side effects.
[中]获取由key参数标识的上下文。
这种方法没有副作用。

代码示例

代码示例来源:origin: org.slf4j/slf4j-log4j12

public String get(String key) {
  return (String) org.apache.log4j.MDC.get(key);
}

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

public Object getMdc(String key) {
  return MDC.get( key );
}

代码示例来源:origin: openzipkin/brave

@Override protected String get(String key) {
 Object result = MDC.get(key);
 return result instanceof String ? (String) result : null;
}

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

public Object getMdc(String key) {
  return MDC.get(key);
}

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

/**
  Returns the the context corresponding to the <code>key</code>
  parameter. If there is a local MDC copy, possibly because we are
  in a logging server or running inside AsyncAppender, then we
  search for the key in MDC copy, if a value is found it is
  returned. Otherwise, if the search in MDC copy returns a null
  result, then the current thread's <code>MDC</code> is used.
  
  <p>Note that <em>both</em> the local MDC copy and the current
  thread's MDC are searched.
*/
public
Object getMDC(String key) {
 Object r;
 // Note the mdcCopy is used if it exists. Otherwise we use the MDC
 // that is associated with the thread.
 if(mdcCopy != null) {
  r = mdcCopy.get(key);
  if(r != null) {
   return r;
  }
 }
 return MDC.get(key);
}

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

/**
  Returns the the context corresponding to the <code>key</code>
  parameter. If there is a local MDC copy, possibly because we are
  in a logging server or running inside AsyncAppender, then we
  search for the key in MDC copy, if a value is found it is
  returned. Otherwise, if the search in MDC copy returns a null
  result, then the current thread's <code>MDC</code> is used.
  
  <p>Note that <em>both</em> the local MDC copy and the current
  thread's MDC are searched.
*/
public
Object getMDC(String key) {
 Object r;
 // Note the mdcCopy is used if it exists. Otherwise we use the MDC
 // that is associated with the thread.
 if(mdcCopy != null) {
  r = mdcCopy.get(key);
  if(r != null) {
   return r;
  }
 }
 return MDC.get(key);
}

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

public Object putMdc(String key, Object val) {
  try {
    return MDC.get( key );
  }
  finally {
    MDC.put( key, val );
  }
}

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

public Object putMdc(String key, Object val) {
  try {
    return MDC.get(key);
  } finally {
    MDC.put(key, val);
  }
}

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

/**
  Returns the the context corresponding to the <code>key</code>
  parameter. If there is a local MDC copy, possibly because we are
  in a logging server or running inside AsyncAppender, then we
  search for the key in MDC copy, if a value is found it is
  returned. Otherwise, if the search in MDC copy returns a null
  result, then the current thread's <code>MDC</code> is used.
  
  <p>Note that <em>both</em> the local MDC copy and the current
  thread's MDC are searched.
*/
public
Object getMDC(String key) {
 Object r;
 // Note the mdcCopy is used if it exists. Otherwise we use the MDC
 // that is associated with the thread.
 if(mdcCopy != null) {
  r = mdcCopy.get(key);
  if(r != null) {
   return r;
  }
 }
 return MDC.get(key);
}

代码示例来源:origin: apache/log4j

/**
  Returns the the context corresponding to the <code>key</code>
  parameter. If there is a local MDC copy, possibly because we are
  in a logging server or running inside AsyncAppender, then we
  search for the key in MDC copy, if a value is found it is
  returned. Otherwise, if the search in MDC copy returns a null
  result, then the current thread's <code>MDC</code> is used.
  
  <p>Note that <em>both</em> the local MDC copy and the current
  thread's MDC are searched.
*/
public
Object getMDC(String key) {
 Object r;
 // Note the mdcCopy is used if it exists. Otherwise we use the MDC
 // that is associated with the thread.
 if(mdcCopy != null) {
  r = mdcCopy.get(key);
  if(r != null) {
   return r;
  }
 }
 return MDC.get(key);
}

代码示例来源:origin: apache/log4j

/**
  Returns the the context corresponding to the <code>key</code>
  parameter. If there is a local MDC copy, possibly because we are
  in a logging server or running inside AsyncAppender, then we
  search for the key in MDC copy, if a value is found it is
  returned. Otherwise, if the search in MDC copy returns a null
  result, then the current thread's <code>MDC</code> is used.
  
  <p>Note that <em>both</em> the local MDC copy and the current
  thread's MDC are searched.
*/
public
Object getMDC(String key) {
 Object r;
 // Note the mdcCopy is used if it exists. Otherwise we use the MDC
 // that is associated with the thread.
 if(mdcCopy != null) {
  r = mdcCopy.get(key);
  if(r != null) {
   return r;
  }
 }
 return MDC.get(key);
}

代码示例来源:origin: io.tracee.backend/tracee-log4j

@Override
protected String getFromMdc(String key) {
  final Object mdcValue = MDC.get(key);
  if (mdcValue == null) {
    return null;
  }
  return String.valueOf(mdcValue);
}

代码示例来源:origin: apache/activemq-artemis

public Object putMdc(String key, Object val) {
  try {
    return MDC.get(key);
  } finally {
    MDC.put(key, val);
  }
}

代码示例来源:origin: weld/core

public Object putMdc(String key, Object val) {
  try {
    return MDC.get(key);
  } finally {
    MDC.put(key, val);
  }
}

代码示例来源:origin: org.jboss.weld.se/weld-se

public Object putMdc(String key, Object val) {
  try {
    return MDC.get(key);
  } finally {
    MDC.put(key, val);
  }
}

代码示例来源:origin: org.jboss.weld.se/weld-se-shaded

public Object putMdc(String key, Object val) {
  try {
    return MDC.get(key);
  } finally {
    MDC.put(key, val);
  }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

public Object putMdc(String key, Object val) {
  try {
    return MDC.get(key);
  } finally {
    MDC.put(key, val);
  }
}

代码示例来源:origin: org.apache.knox/gateway-util-common

@Override
public AuditContext detachContext() {
 AuditContext context = (AuditContext) MDC.get( MDC_AUDIT_CONTEXT_KEY );
 MDC.remove( MDC_AUDIT_CONTEXT_KEY );
 return context;
}

代码示例来源:origin: apache/activemq-artemis

public Object putMdc(String key, Object val) {
  try {
    return MDC.get(key);
  } finally {
    MDC.put(key, val);
  }
}

代码示例来源:origin: com.nesscomputing.components/ness-serverinfo

@Test
public void testValue()
{
  ServerInfo.add("hello", "world");
  Assert.assertEquals("world", ServerInfo.get("hello"));
  Assert.assertEquals("world", MDC.get("hello").toString());
}

相关文章