Repository: logging-log4j2
Updated Branches:
  refs/heads/master 231241c3f -> dd658d916


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/dd658d91
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/dd658d91
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/dd658d91

Branch: refs/heads/master
Commit: dd658d916d9ada02d8140971a7f22e3d97b46bc0
Parents: 231241c
Author: ggregory <[email protected]>
Authored: Wed Sep 30 22:03:48 2015 -0700
Committer: ggregory <[email protected]>
Committed: Wed Sep 30 22:03:48 2015 -0700

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dd658d91/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