All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.log.MDC Maven / Gradle / Ivy

package panda.log;

import java.util.HashMap;
import java.util.Map;

/**
 * The MDC class provides mapped diagnostic contexts. 
 * A Mapped Diagnostic Context, or MDC in short, is an instrument for distinguishing interleaved log output from different sources. 
 * Log output is typically interleaved when a server handles multiple clients near-simultaneously.
 * 
 * The MDC is managed on a per thread basis. 
 * A child thread automatically inherits a copy of the mapped diagnostic context of its parent.
 */
public class MDC {
	private static final ThreadLocal> tlm = new ThreadLocal>() {
		@Override
		protected Map initialValue() {
			return new HashMap();
		}
	};
	
	public static Object put(String key, Object obj) {
		return tlm.get().put(key, obj);
	}
	
	public static Object get(String key) {
		return tlm.get().get(key);
	}
	
	public static Object remove(String key) {
		return tlm.get().remove(key);
	}
	
	public static Map map() {
		return tlm.get();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy