package org.grouplens.lenskit.util;

import org.slf4j.MDC;

import java.util.Map;

/**
 * Utility class to manage log data with {@link MDC}.  This class allows MDC parameters
 * to be set, and popped back off when the context is finished.
 */
public class LogContext {
    private final Map memory = MDC.getCopyOfContextMap();

    /**
     * Set a key in the MDC environment.
     * @param key The key to set.
     * @param value The key's value.
     * @see {@link MDC#put(String, String)}
     */
    public void put(String key, String value) {
        MDC.put(key, value);
    }

    /**
     * Finish the context.  This restores the MDC context map to the value it had when the
     * log context was created.
     */
    public void finish() {
        MDC.setContextMap(memory);
    }
}

@@ -53,16 +53,46 @@
 j.MDC;%0A%0A
+import java.util.Collections;%0A
 import j
@@ -805,16 +805,57 @@
 p(memory
+ == null ? Collections.EMPTY_MAP : memory
 );%0A    %7D

fix log context bug