logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1555454 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java log4j-core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java src/changes/changes.xml
Date Sun, 05 Jan 2014 04:21:49 GMT
Author: rgoers
Date: Sun Jan  5 04:21:49 2014
New Revision: 1555454

URL: http://svn.apache.org/r1555454
Log:
LOG4J2-430 - Use the formatted Message in RFC5424Layout for non-StructuredDataMessages

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java?rev=1555454&r1=1555453&r2=1555454&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
Sun Jan  5 04:21:49 2014
@@ -324,7 +324,8 @@ public class RFC5424Layout extends Abstr
 
     private void appendMessage(final StringBuilder buffer, final LogEvent event) {
         final Message message = event.getMessage();
-        final String text = message.getFormat();
+        // This layout formats StructuredDataMessages instead of delegating to the Message
itself.
+        final String text = (message instanceof StructuredDataMessage) ? message.getFormat()
: message.getFormattedMessage();
 
         if (text != null && text.length() > 0) {
             buffer.append(" ").append(escapeNewlines(text, escapeNewLine));

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java?rev=1555454&r1=1555453&r2=1555454&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
Sun Jan  5 04:21:49 2014
@@ -242,7 +242,7 @@ public class RFC5424LayoutTest {
 
             assertTrue("Not enough list entries", list.size() > 1);
             final String string = list.get(1);
-			assertTrue("No Exception in " + string, string.contains("IllegalArgumentException"));
+			      assertTrue("No Exception in " + string, string.contains("IllegalArgumentException"));
 
             appender.clear();
         } finally {
@@ -424,4 +424,31 @@ public class RFC5424LayoutTest {
             appender.stop();
         }
     }
+
+    @Test
+    public void testParameterizedMessage() {
+        for (final Appender appender : root.getAppenders().values()) {
+            root.removeAppender(appender);
+        }
+        // set up appender
+        final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
+            null, null, "true", null, "ATM", null, "key1, key2, locale", null, null, null,
"true", null, null);
+        final ListAppender appender = new ListAppender("List", null, layout, true, false);
+
+        appender.start();
+
+        // set appender on root and set level to debug
+        root.addAppender(appender);
+        root.setLevel(Level.DEBUG);
+        root.info("Hello {}", "World");
+        try {
+            final List<String> list = appender.getMessages();
+            assertTrue("Not enough list entries", list.size() > 0);
+            String message =  list.get(0);
+            assertTrue("Incorrect message. Expected - Hello World, Actual - " + message,
message.contains("Hello World"));
+        } finally {
+            root.removeAppender(appender);
+            appender.stop();
+        }
+    }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1555454&r1=1555453&r2=1555454&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Jan  5 04:21:49 2014
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-RC1" date="2013-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-430" dev="rgoers" type="fix" due-to="David Gstir">
+        Use the formatted Message in RFC5424Layout for non-StructuredDataMessages.
+      </action>
       <action issue="LOG4J2-459" dev="rgoers" type="fix">
         Set external context when constructing the LoggerContext.
       </action>



Mime
View raw message