io.tracee.backend.log4j.Log4jMdcLikeAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tracee-log4j Show documentation
Show all versions of tracee-log4j Show documentation
Please refer to https://github.com/tracee/tracee.
package io.tracee.backend.log4j;
import io.tracee.MDCLike;
import org.apache.log4j.MDC;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
class Log4jMdcLikeAdapter implements MDCLike {
@Override
public boolean containsKey(String key) {
return MDC.get(key) != null;
}
@Override
public void put(String key, String value) {
MDC.put(key, value);
}
@Override
public String get(String key) {
return (String) MDC.get(key);
}
@Override
public void remove(String key) {
MDC.remove(key);
}
@Override
public Map getCopyOfContext() {
final HashMap copy = new HashMap();
final Hashtable context = MDC.getContext();
final Enumeration keys = context.keys();
while (keys.hasMoreElements()) {
final String key = (String) keys.nextElement();
copy.put(key, (String) context.get(key));
}
return copy;
}
}