logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1487936 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/message/ core/src/main/java/org/apache/logging/log4j/core/appender/ core/src/main/java/org/apache/logging/log4j/core/layout/ core/src/test/java/org/apache...
Date Thu, 30 May 2013 17:14:18 GMT
Author: rgoers
Date: Thu May 30 17:14:17 2013
New Revision: 1487936

URL: http://svn.apache.org/r1487936
Log:
LOG4J2-263 - Do not allow a charset on RFC5424Layout - use UTF-8

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java?rev=1487936&r1=1487935&r2=1487936&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
Thu May 30 17:14:17 2013
@@ -21,8 +21,8 @@ import java.util.Map;
 import org.apache.logging.log4j.util.EnglishEnums;
 
 /**
- * Represents a Message that conforms to RFC 5424.
- * 
+ * Represents a Message that conforms to an RFC 5424 StructuredData element along with the
syslog message.
+ *
  * @see <a href="https://tools.ietf.org/html/rfc5424">RFC 5424</a>
  */
 public class StructuredDataMessage extends MapMessage {
@@ -189,9 +189,18 @@ public class StructuredDataMessage exten
 
     @Override
     protected void validate(final String key, final String value) {
+        validateKey(key);
+    }
+
+    private void validateKey(final String key) {
         if (key.length() > MAX_LENGTH) {
-            throw new IllegalArgumentException("Structured data keys are limited to 32 characters.
key: " + key +
-                " value: " + value);
+            throw new IllegalArgumentException("Structured data keys are limited to 32 characters.
key: " + key);
+        }
+        char[] chars = key.toCharArray();
+        for (char c : chars) {
+            if (c < 33 || c > 126 || c == '=' || c == ']' || c == '"') {
+                throw new IllegalArgumentException("Structured data keys must contain printable
US ASCII characters and may not contain a space, =, ], or \"");
+            }
         }
     }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java?rev=1487936&r1=1487935&r2=1487936&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/SyslogAppender.java
Thu May 30 17:14:17 2013
@@ -123,7 +123,7 @@ public class SyslogAppender<T extends Se
         @SuppressWarnings("unchecked")
         final Layout<S> layout = (Layout<S>)(RFC5424.equalsIgnoreCase(format)
?
             RFC5424Layout.createLayout(facility, id, ein, includeMDC, mdcId, mdcPrefix, eventPrefix,
includeNL,
-                escapeNL, appName, msgId, excludes, includes, required, charsetName, exceptionPattern,
config) :
+                escapeNL, appName, msgId, excludes, includes, required, exceptionPattern,
config) :
             SyslogLayout.createLayout(facility, includeNL, escapeNL, charsetName));
 
         if (name == null) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java?rev=1487936&r1=1487935&r2=1487936&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
Thu May 30 17:14:17 2013
@@ -50,7 +50,7 @@ import java.util.regex.Pattern;
 
 /**
  * Formats a log event in accordance with RFC 5424.
- * 
+ *
  * @see <a href="https://tools.ietf.org/html/rfc5424">RFC 5424</a>
  */
 @Plugin(name = "RFC5424Layout", category = "Core", elementType = "layout", printObject =
true)
@@ -497,7 +497,6 @@ public final class RFC5424Layout extends
      * @param excludes A comma separated list of mdc keys that should be excluded from the
LogEvent.
      * @param includes A comma separated list of mdc keys that should be included in the
FlumeEvent.
      * @param required A comma separated list of mdc keys that must be present in the MDC.
-     * @param charsetName The character set.
      * @param exceptionPattern The pattern for formatting exceptions.
      * @param config The Configuration. Some Converters require access to the Interpolator.
      * @return An RFC5424Layout.
@@ -517,10 +516,9 @@ public final class RFC5424Layout extends
                                              @PluginAttr("mdcExcludes") final String excludes,
                                              @PluginAttr("mdcIncludes") String includes,
                                              @PluginAttr("mdcRequired") final String required,
-                                             @PluginAttr("charset") final String charsetName,
                                              @PluginAttr("exceptionPattern") final String
exceptionPattern,
                                              @PluginConfiguration final Configuration config)
{
-        final Charset charset = Charsets.getSupportedCharset(charsetName);
+        final Charset charset = Charsets.UTF_8;
         if (includes != null && excludes != null) {
             LOGGER.error("mdcIncludes and mdcExcludes are mutually exclusive. Includes wil
be ignored");
             includes = null;

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java?rev=1487936&r1=1487935&r2=1487936&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
Thu May 30 17:14:17 2013
@@ -81,7 +81,7 @@ public class RFC5424LayoutTest {
         }
         // set up appender
         final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
-            null, null, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
null, null, null);
+            null, null, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
null, null);
         final ListAppender<String> appender = new ListAppender<String>("List",
null, layout, true, false);
 
         appender.start();
@@ -145,7 +145,7 @@ public class RFC5424LayoutTest {
         }
         // set up appender
         final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
-            null, null, "true", "#012", "ATM", null, "key1, key2, locale", null, "loginId",
null, null, null);
+            null, null, "true", "#012", "ATM", null, "key1, key2, locale", null, "loginId",
null, null);
         final ListAppender<String> appender = new ListAppender<String>("List",
null, layout, true, false);
 
         appender.start();
@@ -208,7 +208,7 @@ public class RFC5424LayoutTest {
         }
         // set up appender
         final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
-            null, null, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
null, "%xEx", null);
+            null, null, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
"%xEx", null);
         final ListAppender<String> appender = new ListAppender<String>("List",
null, layout, true, false);
         appender.start();
 

Modified: logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java?rev=1487936&r1=1487935&r2=1487936&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java
Thu May 30 17:14:17 2013
@@ -198,7 +198,7 @@ public final class FlumeAppender<T exten
         if (layout == null) {
             @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
             Layout<S> l = (Layout<S>)RFC5424Layout.createLayout(null, null, null,
"True", null, mdcPrefix, eventPrefix,
-                    null, null, null, excludes, includes, required, null, null, null, null);
+                    null, null, null, excludes, includes, required, null, null, null);
             layout = l;
         }
 

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1487936&r1=1487935&r2=1487936&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Thu May 30 17:14:17 2013
@@ -22,6 +22,9 @@
   </properties>
   <body>
     <release version="2.0-beta7" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-263" dev="rgoers" type="fix">
+        Do not allow a charset on RFC5424Layout - use UTF-8.
+      </action>
       <action issue="LOG4J2-242" dev="rgoers" type="fix">
         StringFormattedMessage and MessageFormatMessage now will accept a Throwable as their
last argument and
         pass it on.



Mime
View raw message