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

io.tracee.backend.log4j.Log4jMdcLikeAdapter Maven / Gradle / Ivy

There is a newer version: 0.11.0
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy