本文整理了Java中org.apache.log4j.MDC
类的一些代码示例,展示了MDC
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MDC
类的具体详情如下:
包路径:org.apache.log4j.MDC
类名称:MDC
[英]Wrap the PaxContext with MDC api. PaxContext is derived from original MDC.
[中]用MDC api包装PaxContext。PaxContext源于原始MDC。
代码示例来源:origin: hibernate/hibernate-orm
public Object putMdc(String key, Object val) {
try {
return MDC.get( key );
}
finally {
MDC.put( key, val );
}
}
代码示例来源:origin: org.freemarker/freemarker
/**
* Returns if Log4j-over-SLF4J is actually working. Sometimes the API classes are present, but there's no SLF4J
* implementation around.
*/
public static final boolean test() {
org.apache.log4j.MDC.put(MDC_KEY, "");
try {
return org.slf4j.MDC.get(MDC_KEY) != null;
} finally {
org.apache.log4j.MDC.remove(MDC_KEY);
}
}
代码示例来源:origin: log4j/log4j
/**
Obtain a copy of this thread's MDC prior to serialization or
asynchronous logging.
*/
public
void getMDCCopy() {
if(mdcCopyLookupRequired) {
mdcCopyLookupRequired = false;
// the clone call is required for asynchronous logging.
// See also bug #5932.
Hashtable t = (Hashtable) MDC.getContext();
if(t != null) {
mdcCopy = (Hashtable) t.clone();
}
}
}
代码示例来源:origin: org.slf4j/slf4j-log4j12
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setContextMap(Map contextMap) {
Map old = org.apache.log4j.MDC.getContext();
if (old == null) {
Iterator entrySetIterator = contextMap.entrySet().iterator();
while (entrySetIterator.hasNext()) {
Map.Entry mapEntry = (Map.Entry) entrySetIterator.next();
org.apache.log4j.MDC.put((String) mapEntry.getKey(), mapEntry.getValue());
}
} else {
old.clear();
old.putAll(contextMap);
}
}
}
代码示例来源: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: performancecopilot/parfait
public void testClearRemovesMDCValue() {
ThreadContext log4jThreadContext = ThreadContext.newMDCEnabledContext();
Hashtable mdcContext = MDC.getContext();
assertTrue(mdcContext == null || mdcContext.isEmpty());
final String testKey = "painter";
log4jThreadContext.put(testKey, 7);
mdcContext = MDC.getContext();
assertEquals(1, mdcContext.size());
mdcContext.clear();
assertEquals(0, mdcContext.size());
log4jThreadContext.clear();
assertNull("get() after clear should return null", log4jThreadContext.get(testKey));
}
}
代码示例来源:origin: org.ops4j.pax.logging/pax-logging-service
private void clearDelegateContext()
{
m_service.getConfigLock().readLock().unlock();
if( MDC.getContext() != null )
{
MDC.getContext().clear();
}
}
代码示例来源:origin: org.slf4j/slf4j-log4j12
/**
* 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. Log4j does <em>not</em>
* support null for the <code>val</code> parameter.
*
* <p>
* This method delegates all work to log4j's MDC.
*
* @throws IllegalArgumentException
* in case the "key" or <b>"val"</b> parameter is null
*/
public void put(String key, String val) {
org.apache.log4j.MDC.put(key, val);
}
代码示例来源:origin: org.slf4j/slf4j-log4j12
public void remove(String key) {
org.apache.log4j.MDC.remove(key);
}
代码示例来源:origin: apache/knox
@Override
public CorrelationContext detachContext() {
CorrelationContext context = (CorrelationContext) MDC.get( MDC_CORRELATION_CONTEXT_KEY );
MDC.remove( MDC_CORRELATION_CONTEXT_KEY );
return context;
}
代码示例来源:origin: hibernate/hibernate-orm
@SuppressWarnings("unchecked")
public Map<String, Object> getMdcMap() {
return MDC.getContext();
}
代码示例来源:origin: org.slf4j/slf4j-log4j12
public String get(String key) {
return (String) org.apache.log4j.MDC.get(key);
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public void clearMdc() {
MDC.clear();
}
代码示例来源: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: ops4j/org.ops4j.pax.logging
private void clearDelegateContext()
{
m_service.getConfigLock().readLock().unlock();
if( MDC.getContext() != null )
{
MDC.getContext().clear();
}
}
代码示例来源:origin: Alluxio/alluxio
@Override
public int decide(LoggingEvent event) {
MDC.put(REMOTE_LOG_MDC_PROCESS_TYPE_KEY, mProcessType);
return ACCEPT;
}
}
代码示例来源:origin: hibernate/hibernate-orm
public void removeMdc(String key) {
MDC.remove( key );
}
代码示例来源:origin: org.apache.knox/gateway-util-common
@Override
public CorrelationContext detachContext() {
CorrelationContext context = (CorrelationContext) MDC.get( MDC_CORRELATION_CONTEXT_KEY );
MDC.remove( MDC_CORRELATION_CONTEXT_KEY );
return context;
}
代码示例来源:origin: org.slf4j/slf4j-log4j12
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map getCopyOfContextMap() {
Map old = org.apache.log4j.MDC.getContext();
if (old != null) {
return new HashMap(old);
} else {
return null;
}
}
代码示例来源:origin: hibernate/hibernate-orm
public Object getMdc(String key) {
return MDC.get( key );
}
内容来源于网络,如有侵权,请联系作者删除!