bugfix: use OS-independent line separators to run on Windows also

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

Branch: refs/heads/LOG4J2-1136
Commit: 2be1f0f8d737a0ceef65d17a1c0e9d3899ef81fd
Parents: dec3a96
Author: rpopma <[email protected]>
Authored: Thu Sep 24 15:18:03 2015 +0200
Committer: Ralph Goers <[email protected]>
Committed: Sat Oct 3 23:15:31 2015 -0700

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2be1f0f8/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 5ac73a5..90c6b39 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
@@ -309,4 +309,34 @@ public class PatternLayoutTest {
         assertEquals(StandardCharsets.UTF_8, layout.getCharset());
     }
 
+    @Test
+    public void testPatternSelector() throws Exception {
+        PatternMatch[] patterns = new PatternMatch[1];
+        patterns[0] = new PatternMatch("FLOW", "%d %-5p [%t]: ====== 
%C{1}.%M:%L %m ======%n");
+        PatternSelector selector = 
MarkerPatternSelector.createSelector(patterns, "%d %-5p [%t]: %m%n", true, 
true, ctx.getConfiguration());
+        final PatternLayout layout = 
PatternLayout.newBuilder().withPatternSelector(selector)
+                .withConfiguration(ctx.getConfiguration()).build();
+        final LogEvent event1 = Log4jLogEvent.newBuilder() //
+                
.setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.layout.PatternLayoutTest$FauxLogger")
+                .setMarker(MarkerManager.getMarker("FLOW"))
+                .setLevel(Level.TRACE) //
+                .setIncludeLocation(true)
+                .setMessage(new SimpleMessage("entry")).build();
+        final String result1 = new FauxLogger().formatEvent(event1, layout);
+        final String expectSuffix1 = String.format("====== 
PatternLayoutTest.testPatternSelector:281 entry ======%n");
+        assertTrue("Unexpected result: " + result1, 
result1.endsWith(expectSuffix1));
+        final LogEvent event2 = Log4jLogEvent.newBuilder() //
+                
.setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger")
 //
+                .setLevel(Level.INFO) //
+                .setMessage(new SimpleMessage("Hello, world 1!")).build();
+        final String result2 = new String(layout.toByteArray(event2));
+        final String expectSuffix2 = String.format("Hello, world 1!%n");
+        assertTrue("Unexpected result: " + result2, 
result2.endsWith(expectSuffix2));
+    }
+
+    public class FauxLogger {
+        public String formatEvent(LogEvent event, Layout<?> layout) {
+            return new String(layout.toByteArray(event));
+        }
+    }
 }

Reply via email to