Skip to content

Instantly share code, notes, and snippets.

@qerub
Created July 12, 2012 15:45
Show Gist options
  • Save qerub/d21af753dc2b41f84654 to your computer and use it in GitHub Desktop.
Save qerub/d21af753dc2b41f84654 to your computer and use it in GitHub Desktop.
Add org.apache.log4j.MDC.getContext() to log4j-over-slf4j
diff --git a/log4j-over-slf4j/src/main/java/org/apache/log4j/MDC.java b/log4j-over-slf4j/src/main/java/org/apache/log4j/MDC.java
index 5d80884..d16a7ba 100644
--- a/log4j-over-slf4j/src/main/java/org/apache/log4j/MDC.java
+++ b/log4j-over-slf4j/src/main/java/org/apache/log4j/MDC.java
@@ -16,6 +16,9 @@
package org.apache.log4j;
+import java.util.Hashtable;
+import java.util.Map;
+
public class MDC {
public static void put(String key, String value) {
@@ -41,4 +44,15 @@ public class MDC {
public static void clear() {
org.slf4j.MDC.clear();
}
+
+ public static Hashtable getContext() {
+ Map map = org.slf4j.MDC.getCopyOfContextMap();
+
+ if (map != null) {
+ return new Hashtable(map);
+ }
+ else {
+ return new Hashtable();
+ }
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment