logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1177508 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j12-api/src/main/java/org/apache/log4j/ log4j2-api/src/main/java/org/apache/logging/log4j/ log4j2-api/src/test/java/org/apache/logging/log4j/ log4j2-core/src/test/jav...
Date Fri, 30 Sep 2011 04:36:08 GMT
Author: rgoers
Date: Fri Sep 30 04:36:07 2011
New Revision: 1177508

URL: http://svn.apache.org/viewvc?rev=1177508&view=rev
Log:
MDC needs to hold String values only

Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/main/java/org/apache/log4j/MDC.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/StrictXMLConfigTest.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/main/java/org/apache/log4j/MDC.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/main/java/org/apache/log4j/MDC.java?rev=1177508&r1=1177507&r2=1177508&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/main/java/org/apache/log4j/MDC.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/main/java/org/apache/log4j/MDC.java
Fri Sep 30 04:36:07 2011
@@ -18,31 +18,58 @@ package org.apache.log4j;
 
 import org.apache.logging.log4j.ThreadContext;
 
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
 /**
- *
+ * This class behaves just like Log4j's MDC would - and so can cause issues with the redeployment
of web
+ * applications if the Objects stored in the threads Map cannot be garbage collected.
  */
 public final class MDC {
 
+
+    private static ThreadLocal<Map<String, Object>> localMap =
+        new InheritableThreadLocal<Map<String, Object>>() {
+            protected Map<String, Object> initialValue() {
+                return new HashMap<String, Object>();
+            }
+
+            protected Map<String, Object> childValue(Map<String, Object> parentValue)
{
+                return parentValue == null ? new HashMap<String, Object>() : new HashMap<String,
Object>(parentValue);
+            }
+        };
+
     private MDC() {
     }
 
-    public static void put(String key, Object value) {
+
+    public static void put(String key, String value) {
+        localMap.get().put(key, value);
         ThreadContext.put(key, value);
     }
 
-    public static void get(String key) {
-        ThreadContext.get(key);
+
+    public static void put(String key, Object value) {
+        localMap.get().put(key, value);
+        ThreadContext.put(key, value.toString());
+    }
+
+    public static Object get(String key) {
+        return localMap.get().get(key);
     }
 
     public static void remove(String key) {
+        localMap.get().remove(key);
         ThreadContext.remove(key);
     }
 
     public static void clear() {
+        localMap.get().clear();
         ThreadContext.clear();
     }
 
-    public static void getContext() {
-        ThreadContext.getContext();
+    public static Hashtable getContext() {
+        return new Hashtable(localMap.get());
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/ThreadContext.java?rev=1177508&r1=1177507&r2=1177508&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
Fri Sep 30 04:36:07 2011
@@ -31,14 +31,14 @@ import java.util.Stack;
  */
 public final class ThreadContext {
 
-    private static ThreadLocal<Map<String, Object>> localMap =
-        new InheritableThreadLocal<Map<String, Object>>() {
-            protected Map<String, Object> initialValue() {
-                return new HashMap<String, Object>();
+    private static ThreadLocal<Map<String, String>> localMap =
+        new InheritableThreadLocal<Map<String, String>>() {
+            protected Map<String, String> initialValue() {
+                return new HashMap<String, String>();
             }
 
-            protected Map<String, Object> childValue(Map<String, Object> parentValue)
{
-                return parentValue == null ? null : new HashMap<String, Object>(parentValue);
+            protected Map<String, String> childValue(Map<String, String> parentValue)
{
+                return parentValue == null ? new HashMap<String, String>() : new HashMap<String,
String>(parentValue);
             }
         };
 
@@ -69,7 +69,7 @@ public final class ThreadContext {
      * @param key The key name.
      * @param value The key value.
      */
-    public static void put(String key, Object value) {
+    public static void put(String key, String value) {
         localMap.get().put(key, value);
     }
 
@@ -78,9 +78,9 @@ public final class ThreadContext {
      * <p/>
      * <p>This method has no side effects.
      * @param key The key to locate.
-     * @return The value of the object or null.
+     * @return The value associated with the key or null.
      */
-    public static Object get(String key) {
+    public static String get(String key) {
         return localMap.get().get(key);
     }
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/LoggerTest.java?rev=1177508&r1=1177507&r2=1177508&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/LoggerTest.java
Fri Sep 30 04:36:07 2011
@@ -102,7 +102,7 @@ public class LoggerTest {
     @Test
     public void mdc() {
 
-        ThreadContext.put("TestYear", new Integer(2010));
+        ThreadContext.put("TestYear", new Integer(2010).toString());
         logger.debug("Debug message");
         ThreadContext.clear();
         logger.debug("Debug message");

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java?rev=1177508&r1=1177507&r2=1177508&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Fri Sep 30 04:36:07 2011
@@ -132,7 +132,7 @@ public class LoggerTest {
     @Test
     public void mdc() {
 
-        ThreadContext.put("TestYear", new Integer(2010));
+        ThreadContext.put("TestYear", new Integer(2010).toString());
         logger.debug("Debug message");
         ThreadContext.clear();
         logger.debug("Debug message");

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/StrictXMLConfigTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/StrictXMLConfigTest.java?rev=1177508&r1=1177507&r2=1177508&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/StrictXMLConfigTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/StrictXMLConfigTest.java
Fri Sep 30 04:36:07 2011
@@ -133,7 +133,7 @@ public class StrictXMLConfigTest {
     @Test
     public void mdc() {
 
-        ThreadContext.put("TestYear", new Integer(2010));
+        ThreadContext.put("TestYear", new Integer(2010).toString());
         logger.debug("Debug message");
         ThreadContext.clear();
         logger.debug("Debug message");



Mime
View raw message