Refine search
/** * 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); } }
/** 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(); } } }
@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); } } }
/** 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); }
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)); } }
private void clearDelegateContext() { m_service.getConfigLock().readLock().unlock(); if( MDC.getContext() != null ) { MDC.getContext().clear(); } }
/** * 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); }
public void remove(String key) { org.apache.log4j.MDC.remove(key); }
@SuppressWarnings("unchecked") public Map<String, Object> getMdcMap() { return MDC.getContext(); }
public String get(String key) { return (String) org.apache.log4j.MDC.get(key); }
@Override public void clearMdc() { MDC.clear(); }
/** 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); }
private void clearDelegateContext() { m_service.getConfigLock().readLock().unlock(); if( MDC.getContext() != null ) { MDC.getContext().clear(); } }
@Override public int decide(LoggingEvent event) { MDC.put(REMOTE_LOG_MDC_PROCESS_TYPE_KEY, mProcessType); return ACCEPT; } }
public void removeMdc(String key) { MDC.remove( key ); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Map getCopyOfContextMap() { Map old = org.apache.log4j.MDC.getContext(); if (old != null) { return new HashMap(old); } else { return null; } }
public Object getMdc(String key) { return MDC.get( key ); }