logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1469616 - in /logging/log4j/log4j2/trunk: 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/logging/log4j/core/ core/src/test/java/org/apache/l...
Date Thu, 18 Apr 2013 22:42:21 GMT
Author: rgoers
Date: Thu Apr 18 22:42:21 2013
New Revision: 1469616

URL: http://svn.apache.org/r1469616
Log:
Add mdcPrefix and eventPrefix to RFC5424Layout

Modified:
    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/LoggerTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/RFC5424LayoutTest.java
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeAppender.java
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java
    logging/log4j/log4j2/trunk/flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeAppenderTest.java

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=1469616&r1=1469615&r2=1469616&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 Apr 18 22:42:21 2013
@@ -62,6 +62,8 @@ public class SyslogAppender extends Sock
      * @param includeMDC Indicates whether data from the ThreadContextMap will be included
in the RFC 5424 Syslog
      * record. Defaults to "true:.
      * @param mdcId The id to use for the MDC Structured Data Element.
+     * @param mdcPrefix The prefix to add to MDC key names.
+     * @param eventPrefix The prefix to add to event key names.
      * @param includeNL If true, a newline will be appended to the end of the syslog record.
The default is false.
      * @param escapeNL String that should be used to replace newlines within the message
text.
      * @param appName The value to use as the APP-NAME in the RFC 5424 syslog record.
@@ -90,6 +92,8 @@ public class SyslogAppender extends Sock
                                                 @PluginAttr("enterpriseNumber") final String
ein,
                                                 @PluginAttr("includeMDC") final String includeMDC,
                                                 @PluginAttr("mdcId") final String mdcId,
+                                                @PluginAttr("mdcPrefix") final String mdcPrefix,
+                                                @PluginAttr("eventPrefix") final String eventPrefix,
                                                 @PluginAttr("newLine") final String includeNL,
                                                 @PluginAttr("newLineEscape") final String
escapeNL,
                                                 @PluginAttr("appName") final String appName,
@@ -110,8 +114,8 @@ public class SyslogAppender extends Sock
         final int port = portNum == null ? 0 : Integer.parseInt(portNum);
         boolean isAdvertise = advertise == null ? false : Boolean.valueOf(advertise);
         final Layout<String> layout = RFC5424.equalsIgnoreCase(format) ?
-            RFC5424Layout.createLayout(facility, id, ein, includeMDC, mdcId, includeNL, escapeNL,
appName,
-                msgId, excludes, includes, required, charsetName, exceptionPattern, config)
:
+            RFC5424Layout.createLayout(facility, id, ein, includeMDC, mdcId, mdcPrefix, eventPrefix,
includeNL,
+                escapeNL, appName, msgId, excludes, includes, required, charsetName, 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=1469616&r1=1469615&r2=1469616&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 Apr 18 22:42:21 2013
@@ -88,6 +88,8 @@ public final class RFC5424Layout extends
     private final String appName;
     private final String messageId;
     private final String configName;
+    private final String mdcPrefix;
+    private final String eventPrefix;
     private final List<String> mdcExcludes;
     private final List<String> mdcIncludes;
     private final List<String> mdcRequired;
@@ -103,6 +105,7 @@ public final class RFC5424Layout extends
 
     private RFC5424Layout(final Configuration config, final Facility facility, final String
id, final int ein,
                           final boolean includeMDC, final boolean includeNL, final String
escapeNL, final String mdcId,
+                          final String mdcPrefix, final String eventPrefix,
                           final String appName, final String messageId, final String excludes,
final String includes,
                           final String required, final Charset charset, final String exceptionPattern)
{
         super(charset);
@@ -115,6 +118,8 @@ public final class RFC5424Layout extends
         this.includeNewLine = includeNL;
         this.escapeNewLine = escapeNL == null ? null : Matcher.quoteReplacement(escapeNL);
         this.mdcId = mdcId;
+        this.mdcPrefix = mdcPrefix;
+        this.eventPrefix = eventPrefix;
         this.appName = appName;
         this.messageId = messageId;
         this.localHostName = NetUtils.getLocalHostname();
@@ -243,7 +248,7 @@ public final class RFC5424Layout extends
                 final StructuredDataMessage data = (StructuredDataMessage) msg;
                 final Map<String, String> map = data.getData();
                 id = data.getId();
-                formatStructuredElement(id, map, buf, noopChecker);
+                formatStructuredElement(id, eventPrefix, map, buf, noopChecker);
                 text = data.getFormat();
             } else {
                 text = msg.getFormattedMessage();
@@ -256,7 +261,7 @@ public final class RFC5424Layout extends
                 final int ein = id == null || id.getEnterpriseNumber() < 0 ?
                     enterpriseNumber : id.getEnterpriseNumber();
                 final StructuredDataId mdcSDID = new StructuredDataId(mdcId, ein, null, null);
-                formatStructuredElement(mdcSDID, map, buf, checker);
+                formatStructuredElement(mdcSDID, mdcPrefix, map, buf, checker);
             }
             if (text != null && text.length() > 0) {
                 buf.append(" ").append(escapeNewlines(text, escapeNewLine));
@@ -363,14 +368,14 @@ public final class RFC5424Layout extends
         buf.append(Integer.toString(val));
     }
 
-    private void formatStructuredElement(final StructuredDataId id, final Map<String,
String> data,
+    private void formatStructuredElement(final StructuredDataId id, final String prefix,
final Map<String, String> data,
                                          final StringBuilder sb, final ListChecker checker)
{
         if (id == null && defaultId == null) {
             return;
         }
         sb.append("[");
         sb.append(getId(id));
-        appendMap(data, sb, checker);
+        appendMap(prefix, data, sb, checker);
         sb.append("]");
     }
 
@@ -400,24 +405,18 @@ public final class RFC5424Layout extends
         }
     }
 
-    private void appendMap(final Map<String, String> map, final StringBuilder sb, final
ListChecker checker)
+    private void appendMap(final String prefix, final Map<String, String> map, final
StringBuilder sb,
+                           final ListChecker checker)
     {
         final SortedMap<String, String> sorted = new TreeMap<String, String>(map);
         for (final Map.Entry<String, String> entry : sorted.entrySet()) {
             if (checker.check(entry.getKey()) && entry.getValue() != null) {
-                sb
-                        .append(" ")
-                        .append(escapeNewlines(
-                        		escapeSDParams(
-                        				entry.getKey()),
-                                escapeNewLine))
-                        .append("=\"")
-                        .append(
-                                escapeNewlines(
-                                        escapeSDParams(
-                                                entry.getValue()),
-                                        escapeNewLine))
-                        .append("\"");
+                sb.append(" ");
+                if (prefix != null) {
+                    sb.append(prefix);
+                }
+                sb.append(escapeNewlines(escapeSDParams(entry.getKey()),escapeNewLine)).append("=\"")
+                  .append(escapeNewlines(escapeSDParams(entry.getValue()),escapeNewLine)).append("\"");
             }
         }
     }
@@ -482,6 +481,8 @@ public final class RFC5424Layout extends
      * @param includeMDC Indicates whether data from the ThreadContextMap will be included
in the RFC 5424 Syslog
      * record. Defaults to "true:.
      * @param mdcId The id to use for the MDC Structured Data Element.
+     * @param mdcPrefix The prefix to add to MDC key names.
+     * @param eventPrefix The prefix to add to event key names.
      * @param includeNL If true, a newline will be appended to the end of the syslog record.
The default is false.
      * @param escapeNL String that should be used to replace newlines within the message
text.
      * @param appName The value to use as the APP-NAME in the RFC 5424 syslog record.
@@ -500,6 +501,8 @@ public final class RFC5424Layout extends
                                              @PluginAttr("enterpriseNumber") final String
ein,
                                              @PluginAttr("includeMDC") final String includeMDC,
                                              @PluginAttr("mdcId") String mdcId,
+                                             @PluginAttr("mdcPrefix") String mdcPrefix,
+                                             @PluginAttr("eventPrefix") String eventPrefix,
                                              @PluginAttr("newLine") final String includeNL,
                                              @PluginAttr("newLineEscape") final String escapeNL,
                                              @PluginAttr("appName") final String appName,
@@ -523,7 +526,7 @@ public final class RFC5424Layout extends
             mdcId = DEFAULT_MDCID;
         }
 
-        return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine,
escapeNL, mdcId, appName,
-                                 msgId, excludes, includes, required, charset, exceptionPattern);
+        return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine,
escapeNL, mdcId, mdcPrefix,
+                                 eventPrefix, appName, msgId, excludes, includes, required,
charset, exceptionPattern);
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java?rev=1469616&r1=1469615&r2=1469616&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Thu Apr 18 22:42:21 2013
@@ -255,5 +255,11 @@ public class LoggerTest {
         assertNotNull("No configuration", cfg);
         assertTrue("Reconfiguration failed", cfg != config);
     }
+
+    @Test
+    public void testAdditivity() throws Exception {
+        Logger localLogger = (Logger) LogManager.getLogger("org.apache.test");
+
+    }
 }
 

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java?rev=1469616&r1=1469615&r2=1469616&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SyslogAppenderTest.java
Thu Apr 18 22:42:21 2013
@@ -211,8 +211,8 @@ public class SyslogAppenderTest {
 
     private SyslogAppender createAppender(final String protocol, final String format) {
         return SyslogAppender.createAppender("localhost", PORT, protocol, "-1", "Test", "true",
"false", "LOCAL0", "Audit",
-            "18060", "true", "RequestContext", "true", null, "TestApp", "Test", null, "ipAddress,loginId",
null, format, null,
-                null, null, null, null);
+            "18060", "true", "RequestContext", null, null, "true", null, "TestApp", "Test",
null, "ipAddress,loginId",
+            null, format, null, null, null, null, null);
     }
 
     public static class UDPSocketServer extends Thread {

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=1469616&r1=1469615&r2=1469616&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 Apr 18 22:42:21 2013
@@ -52,7 +52,7 @@ public class RFC5424LayoutTest {
         "ATM - Audit [Transfer@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"]"
+
         "[RequestContext@18060 ipAddress=\"192.168.0.120\" loginId=\"JohnDoe\"] Transfer
Complete";
     private static final String lineEscaped3 = "ATM - - [RequestContext@3692 escaped=\"Testing
escaping #012 \\\" \\] \\\"\" loginId=\"JohnDoe\"] filled mdc";
-    private static final String lineEscaped4 = 
+    private static final String lineEscaped4 =
         "ATM - Audit [Transfer@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"]"
+
         "[RequestContext@18060 escaped=\"Testing escaping #012 \\\" \\] \\\"\" ipAddress=\"192.168.0.120\"
loginId=\"JohnDoe\"] Transfer Complete";
 
@@ -81,7 +81,7 @@ public class RFC5424LayoutTest {
         }
         // set up appender
         final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
-            "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, null);
         final ListAppender appender = new ListAppender("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",
-            "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, null);
         final ListAppender appender = new ListAppender("List", null, layout, true, false);
 
         appender.start();
@@ -153,7 +153,7 @@ public class RFC5424LayoutTest {
         // set appender on root and set level to debug
         root.addAppender(appender);
         root.setLevel(Level.DEBUG);
-        
+
         ThreadContext.put("loginId", "JohnDoe");
 
         // output starting message
@@ -208,7 +208,7 @@ public class RFC5424LayoutTest {
         }
         // set up appender
         final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
-            "true", null, "ATM", null, "key1, key2, locale", null, "loginId", null, "%xEx",
null);
+            null, null, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
null, "%xEx", null);
         final ListAppender appender = new ListAppender("List", null, layout, true, false);
         appender.start();
 

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml?rev=1469616&r1=1469615&r2=1469616&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml Thu Apr 18 22:42:21
2013
@@ -72,8 +72,8 @@
 
     <logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
       <appender-ref ref="File"/>
-    </logger>>
-
+    </logger>
+    <logger name="org" level="error" additivity="true"/>
     <root level="trace">
       <appender-ref ref="List"/>
     </root>

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=1469616&r1=1469615&r2=1469616&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 Apr 18 22:42:21 2013
@@ -194,8 +194,8 @@ public final class FlumeAppender extends
 
 
         if (layout == null) {
-            layout = RFC5424Layout.createLayout(null, null, null, "True", null, null, null,
null, excludes,
-                includes, required, null, null, null, null);
+            layout = RFC5424Layout.createLayout(null, null, null, "True", null, mdcPrefix,
eventPrefix, null, null,
+                null, excludes, includes, required, null, null, null, null);
         }
 
         if (name == null) {

Modified: logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java?rev=1469616&r1=1469615&r2=1469616&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java
Thu Apr 18 22:42:21 2013
@@ -125,8 +125,10 @@ public class FlumeEvent extends SimpleEv
                 }
             }
         }
+        final String guid =  UUIDUtil.getTimeBasedUUID().toString();
         final Message message = event.getMessage();
         if (message instanceof MapMessage) {
+            ((MapMessage) message).put(GUID, guid);
             if (message instanceof StructuredDataMessage) {
                 addStructuredData(eventPrefix, headers, (StructuredDataMessage) message);
             }
@@ -134,8 +136,6 @@ public class FlumeEvent extends SimpleEv
         }
 
         addContextData(mdcPrefix, headers, ctx);
-
-        addGuid(headers);
     }
 
     protected void addStructuredData(final String prefix, final Map<String, String>
fields,
@@ -161,10 +161,6 @@ public class FlumeEvent extends SimpleEv
         }
     }
 
-    protected void addGuid(final Map<String, String> fields) {
-        fields.put(GUID, UUIDUtil.getTimeBasedUUID().toString());
-    }
-
     /**
      * Set the body in the event.
      * @param body The body to add to the event.

Modified: logging/log4j/log4j2/trunk/flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeAppenderTest.java?rev=1469616&r1=1469615&r2=1469616&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeAppenderTest.java
Thu Apr 18 22:42:21 2013
@@ -156,14 +156,14 @@ public class FlumeAppenderTest {
     public void testStructured() throws InterruptedException, IOException {
         final Agent[] agents = new Agent[] {Agent.createAgent("localhost", testPort)};
         final FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, "false",
"Avro", null, "1000",
-            "1000", "1", "1000", "avro", "false", null, null, null, null, null, "true", "1",
null, null, null);
+            "1000", "1", "1000", "avro", "false", null, null, null, "ReqCtx_", null, "true",
"1", null, null, null);
         avroAppender.start();
         final Logger eventLogger = (Logger) LogManager.getLogger("EventLogger");
         Assert.assertNotNull(eventLogger);
         eventLogger.addAppender(avroAppender);
         eventLogger.setLevel(Level.ALL);
 
-        final StructuredDataMessage msg = new StructuredDataMessage("Tranfser", "Success",
"Audit");
+        final StructuredDataMessage msg = new StructuredDataMessage("Transfer", "Success",
"Audit");
         msg.put("memo", "This is a memo");
         msg.put("acct", "12345");
         msg.put("amount", "100.00");
@@ -180,6 +180,7 @@ public class FlumeAppenderTest {
         Assert.assertNotNull(event);
         Assert.assertTrue("Channel contained event, but not expected message",
             getBody(event).endsWith("Success"));
+        System.out.println(getBody(event));
         transaction.commit();
         transaction.close();
 



Mime
View raw message