logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r823968 - in /logging/log4j/trunk: src/changes/changes.xml src/main/java/org/apache/log4j/MDC.java tests/src/java/org/apache/log4j/PatternLayoutTestCase.java tests/witness/patternLayout.mdc.clear
Date Sat, 10 Oct 2009 22:15:20 GMT
Author: carnold
Date: Sat Oct 10 22:15:19 2009
New Revision: 823968

URL: http://svn.apache.org/viewvc?rev=823968&view=rev
Log:
Bug 47107: Add MDC.clear() method

Added:
    logging/log4j/trunk/tests/witness/patternLayout.mdc.clear
Modified:
    logging/log4j/trunk/src/changes/changes.xml
    logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java
    logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java

Modified: logging/log4j/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=823968&r1=823967&r2=823968&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Sat Oct 10 22:15:19 2009
@@ -85,6 +85,7 @@
        <action action="fix" issue="47967">log4j.ignoreTCL should apply to the getResource
method in addition to the loadClass method of org.apache.log4j.helpers.Loader.</action>
        <action action="fix" issue="46539">The QuietWriter class does not live up to
its published contract.</action>
        <action action="add" issue="46983">More Debug output for log4j auto-configure
requested.</action>
+       <action action="add" issue="47107">Add MDC.clear().</action>
     </release>
 
   

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java?rev=823968&r1=823967&r2=823968&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/MDC.java Sat Oct 10 22:15:19 2009
@@ -115,6 +115,16 @@
     }
   }
 
+  /**
+   *  Remove all values from the MDC.
+   *  @since 1.2.16
+  */
+  public static void clear() {
+    if (mdc != null) {
+        mdc.clear0();
+    }
+  }
+
 
   private
   void put0(String key, Object o) {
@@ -163,4 +173,15 @@
       return (Hashtable) ((ThreadLocalMap)tlm).get();
     }
   }
+
+  private
+  void clear0() {
+    if(!java1 && tlm != null) {
+      Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
+      if(ht != null) {
+        ht.clear();
+      } 
+    }
+  }
+
 }

Modified: logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java?rev=823968&r1=823967&r2=823968&view=diff
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java (original)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/PatternLayoutTestCase.java Sat Oct
10 22:15:19 2009
@@ -288,6 +288,17 @@
       assertTrue(Compare.compare(TEMP, "witness/patternLayout.mdc.1"));
     }
 
+    public void testMDCClear() throws Exception {
+      PropertyConfigurator.configure("input/patternLayout.mdc.1.properties");
+      MDC.put("key1", "va11");
+      MDC.put("key2", "va12");
+      logger.debug("Hello World");
+      MDC.clear();
+      logger.debug("Hello World");
+
+      assertTrue(Compare.compare(TEMP, "witness/patternLayout.mdc.clear"));
+    }
+
 
 
   void common() {

Added: logging/log4j/trunk/tests/witness/patternLayout.mdc.clear
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/witness/patternLayout.mdc.clear?rev=823968&view=auto
==============================================================================
--- logging/log4j/trunk/tests/witness/patternLayout.mdc.clear (added)
+++ logging/log4j/trunk/tests/witness/patternLayout.mdc.clear Sat Oct 10 22:15:19 2009
@@ -0,0 +1,2 @@
+DEBUG - Hello World {{key1,va11}{key2,va12}}
+DEBUG - Hello World {}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message