Add
org.apache.logging.log4j.core.layout.PatternLayoutTest.testRegexEmptyMarker().


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/632f2c23
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/632f2c23
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/632f2c23

Branch: refs/heads/LOG4J2-1136
Commit: 632f2c23997a6e063162ee8d265009e6823d1f72
Parents: a81ec3d
Author: ggregory <[email protected]>
Authored: Wed Sep 30 22:03:48 2015 -0700
Committer: Ralph Goers <[email protected]>
Committed: Sat Oct 3 23:08:04 2015 -0700

----------------------------------------------------------------------
 .../log4j/core/layout/PatternLayoutTest.java    | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/632f2c23/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
index 0b372bb..19a6111 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
@@ -179,6 +179,28 @@ public class PatternLayoutTest {
     }
 
     @Test
+    public void testRegexEmptyMarker() throws Exception {
+        // replace "[]" with the empty string
+        final PatternLayout layout = 
PatternLayout.newBuilder().withPattern("[%logger]%replace{[%marker]}{\\[\\]}{} 
%msg")
+                .withConfiguration(ctx.getConfiguration()).build();
+        // Not empty marker
+        final LogEvent event1 = Log4jLogEvent.newBuilder() //
+                
.setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger")
 //
+                .setLevel(Level.INFO) //
+                .setMarker(MarkerManager.getMarker("TestMarker")) //
+                .setMessage(new SimpleMessage("Hello, world!")).build();
+        final byte[] result1 = layout.toByteArray(event1);
+        
assertEquals("[org.apache.logging.log4j.core.layout.PatternLayoutTest][TestMarker]
 Hello, world!", new String(result1));
+        // empty marker
+        final LogEvent event2 = Log4jLogEvent.newBuilder() //
+                
.setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger")
 //
+                .setLevel(Level.INFO) //
+                .setMessage(new SimpleMessage("Hello, world!")).build();
+        final byte[] result2 = layout.toByteArray(event2);
+        assertEquals("[org.apache.logging.log4j.core.layout.PatternLayoutTest] 
Hello, world!", new String(result2));
+    }
+
+    @Test
     public void testSpecialChars() throws Exception {
         final PatternLayout layout = 
PatternLayout.newBuilder().withPattern("\\\\%level\\t%msg\\n\\t%logger\\r\\n\\f")
                 .withConfiguration(ctx.getConfiguration()).build();

Reply via email to