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

com.github.valfirst.slf4jtest.TestMDCAdapter Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package com.github.valfirst.slf4jtest;

import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.spi.MDCAdapter;

public class TestMDCAdapter implements MDCAdapter {

    private final ThreadLocal> value = ThreadLocal.withInitial(HashMap::new);

    public void put(final String key, final String val) {
        value.get().put(key, String.valueOf(val));
    }

    public String get(final String key) {
        return value.get().get(key);
    }

    public void remove(final String key) {
        value.get().remove(key);
    }

    public void clear() {
        value.get().clear();
    }

    public ImmutableMap getCopyOfContextMap() {
        return ImmutableMap.copyOf(value.get());
    }

    @SuppressWarnings("unchecked")
    public void setContextMap(final Map contextMap) {
        value.set(new HashMap(contextMap));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy