logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1501806 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/spi/ api/src/test/java/org/apache/logging/log4j/spi/ src/changes/
Date Wed, 10 Jul 2013 15:49:03 GMT
Author: rpopma
Date: Wed Jul 10 15:49:03 2013
New Revision: 1501806

URL: http://svn.apache.org/r1501806
Log:
LOG4J2-302: Added toString methods to ThreadContextStack/Map implementation classes

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/MutableThreadContextStack.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java?rev=1501806&r1=1501805&r2=1501806&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
Wed Jul 10 15:49:03 2013
@@ -139,4 +139,10 @@ public class DefaultThreadContextMap imp
         final Map<String, String> map = localMap.get();
         return map == null || map.size() == 0;
     }
+
+    @Override
+    public String toString() {
+        Map<String, String> map = localMap.get();
+        return map == null ? "{}" : map.toString();
+    }
 }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java?rev=1501806&r1=1501805&r2=1501806&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
Wed Jul 10 15:49:03 2013
@@ -251,4 +251,10 @@ public class DefaultThreadContextStack i
         stack.set(Collections.unmodifiableList(copy));
         return result;
     }
+    
+    @Override
+    public String toString() {
+        final List<String> list = stack.get();
+        return list == null ? "[]" : list.toString();
+    }
 }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/MutableThreadContextStack.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/MutableThreadContextStack.java?rev=1501806&r1=1501805&r2=1501806&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/MutableThreadContextStack.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/MutableThreadContextStack.java
Wed Jul 10 15:49:03 2013
@@ -161,4 +161,9 @@ public class MutableThreadContextStack i
     public boolean retainAll(final Collection<?> objects) {
         return list.retainAll(objects);
     }
+    
+    @Override
+    public String toString() {
+        return String.valueOf(list);
+    }
 }

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java?rev=1501806&r1=1501805&r2=1501806&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
Wed Jul 10 15:49:03 2013
@@ -155,4 +155,17 @@ public class DefaultThreadContextMapTest
 
         assertFalse(immutable.isEmpty());
     }
+    
+    @Test
+    public void testToStringShowsMapContext() {
+        final DefaultThreadContextMap map = new DefaultThreadContextMap(true);
+        assertEquals("{}", map.toString());
+        
+        map.put("key1", "value1");
+        assertEquals("{key1=value1}", map.toString());
+        
+        map.remove("key1");
+        map.put("key2", "value2");
+        assertEquals("{key2=value2}", map.toString());
+    }
 }

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java?rev=1501806&r1=1501805&r2=1501806&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextStackTest.java
Wed Jul 10 15:49:03 2013
@@ -317,4 +317,18 @@ public class DefaultThreadContextStackTe
         assertTrue(stack.contains("msg3"));
     }
 
+    @Test
+    public void testToStringShowsListContents() {
+        final DefaultThreadContextStack stack = new DefaultThreadContextStack(true);
+        stack.clear();
+        assertEquals("[]", stack.toString());
+        
+        stack.push("msg1");
+        stack.add("msg2");
+        stack.push("msg3");
+        assertEquals("[msg1, msg2, msg3]", stack.toString());
+        
+        stack.retainAll(Arrays.asList("msg1", "msg3"));
+        assertEquals("[msg1, msg3]", stack.toString());
+    }
 }

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java?rev=1501806&r1=1501805&r2=1501806&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/spi/MutableThreadContextStackTest.java
Wed Jul 10 15:49:03 2013
@@ -320,4 +320,18 @@ public class MutableThreadContextStackTe
         assertFalse(stack.contains("msg2"));
         assertTrue(stack.contains("msg3"));
     }
+
+    @Test
+    public void testToStringShowsListContents() {
+        final MutableThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>());
+        assertEquals("[]", stack.toString());
+        
+        stack.push("msg1");
+        stack.add("msg2");
+        stack.push("msg3");
+        assertEquals("[msg1, msg2, msg3]", stack.toString());
+        
+        stack.retainAll(Arrays.asList("msg1", "msg3"));
+        assertEquals("[msg1, msg3]", stack.toString());
+    }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1501806&r1=1501805&r2=1501806&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Jul 10 15:49:03 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta8" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-302" dev="rpopma" type="fix">
+        Added toString methods to ThreadContextStack/Map implementation classes.
+      </action>
       <action issue="LOG4J2-301" dev="rgoers" type="update">
         Add printf methods to Logger API.
       </action>



Mime
View raw message