logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1491152 - 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/appender/ core/src/test/java/org...
Date Sun, 09 Jun 2013 07:06:09 GMT
Author: rgoers
Date: Sun Jun  9 07:06:08 2013
New Revision: 1491152

URL: http://svn.apache.org/r1491152
Log:
LOG4J2-168 - Allow elements of the logging event to be added to the mdc structured data in
RFC5424Layout

Added:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java
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/appender/SyslogAppenderTest.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
    logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml
    logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm

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=1491152&r1=1491151&r2=1491152&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
Sun Jun  9 07:06:08 2013
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.LoggerFields;
 import org.apache.logging.log4j.core.layout.RFC5424Layout;
 import org.apache.logging.log4j.core.layout.SyslogLayout;
 import org.apache.logging.log4j.core.net.AbstractSocketManager;
@@ -32,6 +33,7 @@ import org.apache.logging.log4j.core.net
 import org.apache.logging.log4j.util.EnglishEnums;
 
 import java.io.Serializable;
+import java.util.Map;
 
 /**
  * The Syslog Appender.
@@ -112,6 +114,7 @@ public class SyslogAppender<T extends Se
                                                 @PluginConfiguration final Configuration
config,
                                                 @PluginAttr("charset") final String charsetName,
                                                 @PluginAttr("exceptionPattern") final String
exceptionPattern,
+                                                @PluginElement("LoggerFields") LoggerFields
loggerFields,
                                                 @PluginAttr("advertise") final String advertise)
{
 
         final boolean isFlush = immediateFlush == null ? true : Boolean.valueOf(immediateFlush);
@@ -123,7 +126,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, exceptionPattern,
config) :
+                escapeNL, appName, msgId, excludes, includes, required, exceptionPattern,
loggerFields, config) :
             SyslogLayout.createLayout(facility, includeNL, escapeNL, charsetName));
 
         if (name == null) {

Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java?rev=1491152&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java
(added)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/LoggerFields.java
Sun Jun  9 07:06:08 2013
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.layout;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
+
+/**
+ * A LoggerFields container.
+ */
+@Plugin(name = "LoggerFields", category = "Core", printObject = true)
+public final class LoggerFields {
+
+    private Map<String, String> map;
+
+    private LoggerFields(Map<String, String> map) {
+        this.map = Collections.unmodifiableMap(map);
+    }
+
+    public Map<String, String> getMap() {
+        return map;
+    }
+
+    @Override
+    public String toString() {
+        return map.toString();
+    }
+
+    /**
+     * Create a LoggerFields from KeyValuePairs.
+     *
+     * @param keyValuePairs An array of KeyValuePairs.
+     * @return A LoggerFields instance containing a Map<String, String>.
+     */
+    @PluginFactory
+    public static LoggerFields createLoggerFields(
+        @PluginElement("LoggerFields") final KeyValuePair[] keyValuePairs) {
+        final Map<String, String> map =
+            new HashMap<String, String>();
+
+        for (final KeyValuePair keyValuePair : keyValuePairs) {
+            map.put(keyValuePair.getKey(), keyValuePair.getValue());
+        }
+
+        return new LoggerFields(map);
+    }
+}

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=1491152&r1=1491151&r2=1491152&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
Sun Jun  9 07:06:08 2013
@@ -17,18 +17,21 @@
 package org.apache.logging.log4j.core.layout;
 
 import java.util.HashMap;
+
 import org.apache.logging.log4j.LoggingException;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.helpers.Charsets;
 import org.apache.logging.log4j.core.helpers.NetUtils;
 import org.apache.logging.log4j.core.net.Facility;
 import org.apache.logging.log4j.core.net.Priority;
 import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
+import org.apache.logging.log4j.core.pattern.PatternConverter;
 import org.apache.logging.log4j.core.pattern.PatternFormatter;
 import org.apache.logging.log4j.core.pattern.PatternParser;
 import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
@@ -103,16 +106,18 @@ public final class RFC5424Layout extends
     private long lastTimestamp = -1;
     private String timestamppStr;
 
-    private final List<PatternFormatter> formatters;
+    private final List<PatternFormatter> exceptionFormatters;
+    private final Map<String, List<PatternFormatter>> fieldFormatters;
 
     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)
{
+                          final String required, final Charset charset, final String exceptionPattern,
+                          final Map<String, String> loggerFields) {
         super(charset);
-        final PatternParser parser = createPatternParser(config);
-        formatters = exceptionPattern == null ? null : parser.parse(exceptionPattern, false);
+        final PatternParser exceptionParser = createPatternParser(config, ThrowablePatternConverter.class);
+        exceptionFormatters = exceptionPattern == null ? null : exceptionParser.parse(exceptionPattern,
false);
         this.facility = facility;
         this.defaultId = id == null ? DEFAULT_ID : id;
         this.enterpriseNumber = ein;
@@ -171,17 +176,31 @@ public final class RFC5424Layout extends
         this.checker = c != null ? c : noopChecker;
         final String name = config == null ? null : config.getName();
         configName = name != null && name.length() > 0 ? name : null;
+        if (loggerFields != null && !loggerFields.isEmpty()) {
+            final PatternParser fieldParser = createPatternParser(config, null);
+
+            Map<String, List<PatternFormatter>> map = new HashMap<String,
List<PatternFormatter>>();
+            for (Map.Entry<String, String> entry : loggerFields.entrySet()) {
+                List<PatternFormatter> formatters = fieldParser.parse(entry.getValue(),
false);
+                map.put(entry.getKey(), formatters);
+            }
+            this.fieldFormatters = map;
+        } else {
+            this.fieldFormatters = null;
+        }
     }
 
     /**
      * Create a PatternParser.
+     *
      * @param config The Configuration.
      * @return The PatternParser.
      */
-    public static PatternParser createPatternParser(final Configuration config) {
+    public static PatternParser createPatternParser(final Configuration config,
+                                                    final Class<? extends PatternConverter>
filterClass) {
         if (config == null) {
             return new PatternParser(config, PatternLayout.KEY, LogEventPatternConverter.class,
-                ThrowablePatternConverter.class);
+                filterClass);
         }
         PatternParser parser = (PatternParser) config.getComponent(COMPONENT_KEY);
         if (parser == null) {
@@ -196,11 +215,11 @@ public final class RFC5424Layout extends
      * RFC5424Layout's content format is specified by:<p/>
      * Key: "structured" Value: "true"<p/>
      * Key: "format" Value: "RFC5424"<p/>
+     *
      * @return Map of content format keys supporting RFC5424Layout
      */
     @Override
-    public Map<String, String> getContentFormat()
-    {
+    public Map<String, String> getContentFormat() {
         Map<String, String> result = new HashMap<String, String>();
         result.put("structured", "true");
         result.put("formatType", "RFC5424");
@@ -265,6 +284,16 @@ 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);
+                if (fieldFormatters != null) {
+                    map = new HashMap<String, String>(map);
+                    for (final Map.Entry<String, List<PatternFormatter>> entry
: fieldFormatters.entrySet()) {
+                        final StringBuilder value = new StringBuilder();
+                        for (final PatternFormatter formatter : entry.getValue()) {
+                            formatter.format(event, value);
+                        }
+                        map.put(entry.getKey(), value.toString());
+                    }
+                }
                 formatStructuredElement(mdcSDID, mdcPrefix, map, buf, checker);
             }
             if (text != null && text.length() > 0) {
@@ -274,9 +303,9 @@ public final class RFC5424Layout extends
             buf.append("- ");
             buf.append(escapeNewlines(msg.getFormattedMessage(), escapeNewLine));
         }
-        if (formatters != null && event.getThrown() != null) {
+        if (exceptionFormatters != null && event.getThrown() != null) {
             final StringBuilder exception = new StringBuilder("\n");
-            for (final PatternFormatter formatter : formatters) {
+            for (final PatternFormatter formatter : exceptionFormatters) {
                 formatter.format(event, exception);
             }
             buf.append(escapeNewlines(exception.toString(), escapeNewLine));
@@ -287,8 +316,7 @@ public final class RFC5424Layout extends
         return buf.toString();
     }
 
-    private String escapeNewlines(final String text, final String escapeNewLine)
-    {
+    private String escapeNewlines(final String text, final String escapeNewLine) {
         if (null == escapeNewLine) {
             return text;
         }
@@ -410,8 +438,7 @@ public final class RFC5424Layout extends
     }
 
     private void appendMap(final String prefix, final Map<String, String> map, final
StringBuilder sb,
-                           final ListChecker checker)
-    {
+                           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) {
@@ -420,13 +447,12 @@ public final class RFC5424Layout extends
                     sb.append(prefix);
                 }
                 sb.append(escapeNewlines(escapeSDParams(entry.getKey()), escapeNewLine)).append("=\"")
-                  .append(escapeNewlines(escapeSDParams(entry.getValue()), escapeNewLine)).append("\"");
+                    .append(escapeNewlines(escapeSDParams(entry.getValue()), escapeNewLine)).append("\"");
             }
         }
     }
 
-    private String escapeSDParams(String value)
-    {
+    private String escapeSDParams(String value) {
         return PARAM_VALUE_ESCAPE_PATTERN.matcher(value).replaceAll("\\\\$0");
     }
 
@@ -482,23 +508,25 @@ public final class RFC5424Layout extends
 
     /**
      * Create the RFC 5424 Layout.
-     * @param facility The Facility is used to try to classify the message.
-     * @param id The default structured data id to use when formatting according to RFC 5424.
-     * @param ein The IANA enterprise number.
-     * @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.
-     * @param msgId The default value to be used in the MSGID field of RFC 5424 syslog records.
-     * @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 facility         The Facility is used to try to classify the message.
+     * @param id               The default structured data id to use when formatting according
to RFC 5424.
+     * @param ein              The IANA enterprise number.
+     * @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.
+     * @param msgId            The default value to be used in the MSGID field of RFC 5424
syslog records.
+     * @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 exceptionPattern The pattern for formatting exceptions.
-     * @param config The Configuration. Some Converters require access to the Interpolator.
+     * @param loggerFields     Container for the KeyValuePairs containing the patterns
+     * @param config           The Configuration. Some Converters require access to the Interpolator.
      * @return An RFC5424Layout.
      */
     @PluginFactory
@@ -517,6 +545,7 @@ public final class RFC5424Layout extends
                                              @PluginAttr("mdcIncludes") String includes,
                                              @PluginAttr("mdcRequired") final String required,
                                              @PluginAttr("exceptionPattern") final String
exceptionPattern,
+                                             @PluginElement("loggerFields") final LoggerFields
loggerFields,
                                              @PluginConfiguration final Configuration config)
{
         final Charset charset = Charsets.UTF_8;
         if (includes != null && excludes != null) {
@@ -527,11 +556,13 @@ public final class RFC5424Layout extends
         final int enterpriseNumber = ein == null ? DEFAULT_ENTERPRISE_NUMBER : Integer.parseInt(ein);
         final boolean isMdc = includeMDC == null ? true : Boolean.valueOf(includeMDC);
         final boolean includeNewLine = includeNL == null ? false : Boolean.valueOf(includeNL);
+        final Map<String, String> loggerFieldValues = loggerFields == null ? null :
loggerFields.getMap();
         if (mdcId == null) {
             mdcId = DEFAULT_MDCID;
         }
 
         return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine,
escapeNL, mdcId, mdcPrefix,
-                                 eventPrefix, appName, msgId, excludes, includes, required,
charset, exceptionPattern);
+            eventPrefix, appName, msgId, excludes, includes, required, charset, exceptionPattern,
+            loggerFieldValues);
     }
 }

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=1491152&r1=1491151&r2=1491152&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
Sun Jun  9 07:06:08 2013
@@ -211,7 +211,7 @@ public class SyslogAppenderTest {
     private SyslogAppender createAppender(final String protocol, final String format) {
         return SyslogAppender.createAppender("localhost", PORT, protocol, "-1", null, "Test",
"true", "false", "LOCAL0", "Audit",
             "18060", "true", "RequestContext", null, null, "true", null, "TestApp", "Test",
null, "ipAddress,loginId",
-            null, format, null, null, null, null, null);
+            null, format, null, 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=1491152&r1=1491151&r2=1491152&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
Sun Jun  9 07:06:08 2013
@@ -27,6 +27,7 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -81,7 +82,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, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
null, null, null);
         final ListAppender<String> appender = new ListAppender<String>("List",
null, layout, true, false);
 
         appender.start();
@@ -143,9 +144,9 @@ public class RFC5424LayoutTest {
         for (final Appender appender : root.getAppenders().values()) {
             root.removeAppender(appender);
         }
-        // set up appender
+        // set up layout/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, "true", "#012", "ATM", null, "key1, key2, locale", null, "loginId",
null, null, null);
         final ListAppender<String> appender = new ListAppender<String>("List",
null, layout, true, false);
 
         appender.start();
@@ -199,16 +200,16 @@ public class RFC5424LayoutTest {
     }
 
     /**
-     * Test case for MDC conversion pattern.
+     * Test case for MDC exception conversion pattern.
      */
     @Test
     public void testException() throws Exception {
         for (final Appender appender : root.getAppenders().values()) {
             root.removeAppender(appender);
         }
-        // set up appender
+        // set up layout/appender
         final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
-            null, null, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
"%xEx", null);
+            null, null, "true", null, "ATM", null, "key1, key2, locale", null, "loginId",
"%xEx", null, null);
         final ListAppender<String> appender = new ListAppender<String>("List",
null, layout, true, false);
         appender.start();
 
@@ -236,4 +237,45 @@ public class RFC5424LayoutTest {
             appender.stop();
         }
     }
+
+    /**
+     * Test case for MDC logger field inclusion.
+     */
+    @Test
+    public void testMDCLoggerFields() throws Exception {
+        for (final Appender appender : root.getAppenders().values()) {
+            root.removeAppender(appender);
+        }
+        
+        LoggerFields loggerFields = LoggerFields.createLoggerFields(new KeyValuePair[] {
+        		new KeyValuePair("source", "%C.%M")
+        });
+        
+        // set up layout/appender
+        final AbstractStringLayout layout = RFC5424Layout.createLayout("Local0", "Event",
"3692", "true", "RequestContext",
+            null, null, "true", null, "ATM", null, "key1, key2, locale", null, null, null,
loggerFields, null);
+        final ListAppender<String> appender = new ListAppender<String>("List",
null, layout, true, false);
+        appender.start();
+
+        // set appender on root and set level to debug
+        root.addAppender(appender);
+        root.setLevel(Level.DEBUG);
+
+        // output starting message
+        root.info("starting logger fields test");
+
+        try {
+
+            final List<String> list = appender.getMessages();
+            assertTrue("Not enough list entries", list.size() > 0);
+            assertTrue("No class/method", list.get(0).contains("RFC5424LayoutTest.testMDCLoggerFields"));
+
+            appender.clear();
+        } finally {
+            root.removeAppender(appender);
+            ThreadContext.clear();
+
+            appender.stop();
+        }
+    }
 }

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=1491152&r1=1491151&r2=1491152&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
Sun Jun  9 07:06:08 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, excludes, includes, required, null, 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=1491152&r1=1491151&r2=1491152&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Jun  9 07:06:08 2013
@@ -23,6 +23,9 @@
   </properties>
   <body>
     <release version="2.0-beta8" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-168" dev="rgoers" type="update" due-to="Scott Severtson">
+        Allow elements of the logging event to be added to the mdc structured data in RFC5424Layout.
+      </action>
       <action issue="LOG4J2-275" dev="rgoers" type="fix">
         FlumeAvroManager fails to notify client of failing event if Flume RPCClient cannot
be created.
       </action>

Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml?rev=1491152&r1=1491151&r2=1491152&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml Sun Jun  9 07:06:08 2013
@@ -343,7 +343,7 @@
 		                to disk but could impact performance.</p>
 		                <p>Flushing after every write is only useful when using this
 						appender with synchronous loggers. Asynchronous loggers and
-						appenders will automatically flush at the end of a batch of events, 
+						appenders will automatically flush at the end of a batch of events,
 						even if immediateFlush is set to false. This also guarantees
 						the data is written to disk but is more efficient.</p>
 		              </td>
@@ -505,7 +505,7 @@
 		                to disk but could impact performance.</p>
 		                <p>Flushing after every write is only useful when using this
 						appender with synchronous loggers. Asynchronous loggers and
-						appenders will automatically flush at the end of a batch of events, 
+						appenders will automatically flush at the end of a batch of events,
 						even if immediateFlush is set to false. This also guarantees
 						the data is written to disk but is more efficient.</p>
 		              </td>
@@ -697,7 +697,7 @@
                 to disk but could impact performance.</p>
                 <p>Flushing after every write is only useful when using this
 				appender with synchronous loggers. Asynchronous loggers and
-				appenders will automatically flush at the end of a batch of events, 
+				appenders will automatically flush at the end of a batch of events,
 				even if immediateFlush is set to false. This also guarantees
 				the data is written to disk but is more efficient.</p>
               </td>
@@ -878,7 +878,7 @@
               <td>Property[]</td>
               <td><p>One or more Property elements that are used to configure
the Flume Agent. The properties must be
                 configured without the agent name (the appender name is used for this) and
no sources can be
-                configured. Interceptors can be specified for the source using "sources.log4j-source.interceptors".

+                configured. Interceptors can be specified for the source using "sources.log4j-source.interceptors".
                 All other Flume configuration properties are allowed. Specifying both Agent
and Property
                 elements will result in an error.</p>
                 <p>When used to configure in Persistent mode the valid properties are:
@@ -2090,7 +2090,7 @@ public class JpaLogEntity extends LogEve
                 to disk but could impact performance.</p>
                 <p>Flushing after every write is only useful when using this
 				appender with synchronous loggers. Asynchronous loggers and
-				appenders will automatically flush at the end of a batch of events, 
+				appenders will automatically flush at the end of a batch of events,
 				even if immediateFlush is set to false. This also guarantees
 				the data is written to disk but is more efficient.</p>
               </td>
@@ -2639,7 +2639,7 @@ public class JpaLogEntity extends LogEve
             <tr>
               <td>immediateFlush</td>
               <td>boolean</td>
-              <td>When set to true - the default, each write will be followed by a
flush. 
+              <td>When set to true - the default, each write will be followed by a
flush.
                 This will guarantee the data is written
                 to disk but could impact performance.</td>
             </tr>
@@ -2843,6 +2843,15 @@ public class JpaLogEntity extends LogEve
               <td>The default is true, causing exceptions to be internally logged and
then ignored. When set to
                 false exceptions will be percolated to the caller.</td>
             </tr>
+            <tr>
+              <td>loggerFields</td>
+              <td>List of KeyValuePairs</td>
+              <td>Allows arbitrary PatternLayout patterns to be included as specified
ThreadContext fields; no default
+                specified. To use, include a &gt;LoggerFields&lt; nested element,
containing one or more
+                &gt;KeyValuePair&lt; elements. Each &gt;KeyValuePair&lt;
must have a key attribute, which
+                specifies the key name which will be used to identify the field within the
MDC Structured Data element,
+                and a value attribute, whcih specifies the PatternLayout pattern to use as
the value.</td>
+            </tr>
             <caption align="top">SyslogAppender Parameters</caption>
           </table>
           <p>

Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm?rev=1491152&r1=1491151&r2=1491152&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm Sun Jun  9 07:06:08 2013
@@ -1050,6 +1050,15 @@ at org.apache.logging.log4j.core.pattern
                 Defaults to true.</td>
             </tr>
             <tr>
+              <td>loggerFields</td>
+              <td>List of KeyValuePairs</td>
+              <td>Allows arbitrary PatternLayout patterns to be included as specified
ThreadContext fields; no default
+                specified. To use, include a &gt;LoggerFields&lt; nested element,
containing one or more
+                &gt;KeyValuePair&lt; elements. Each &gt;KeyValuePair&lt;
must have a key attribute, which
+                specifies the key name which will be used to identify the field within the
MDC Structured Data element,
+                and a value attribute, whcih specifies the PatternLayout pattern to use as
the value.</td>
+            </tr>
+            <tr>
               <td>mdcExcludes</td>
               <td>String</td>
               <td>A comma separated list of mdc keys that should be excluded from the
LogEvent. This is mutually
@@ -1168,9 +1177,9 @@ at org.apache.logging.log4j.core.pattern
         <subsection name="Location Information">
         <p>
 			If one of the layouts is
-			configured with a location-related attribute like 
+			configured with a location-related attribute like
 			HTML <a href="#HtmlLocationInfo">locationInfo</a>,
-			or one of the patterns 
+			or one of the patterns
 			<a href="#PatternClass">%C or $class</a>,
 			<a href="#PatternFile">%F or %file</a>,
 			<a href="#PatternLocation">%l or %location</a>,
@@ -1183,7 +1192,7 @@ at org.apache.logging.log4j.core.pattern
 			This is an expensive operation: 1.3 - 5 times slower for
 			synchronous loggers. Synchronous loggers wait as
 			long as possible before they take this stack snapshot. If no
-			location is required, the snapshot will never be taken. 
+			location is required, the snapshot will never be taken.
 			</p><p>
 			However,
 			asynchronous loggers need to make this decision before passing the
@@ -1195,8 +1204,8 @@ at org.apache.logging.log4j.core.pattern
 			For this reason, asynchronous loggers and asynchronous
 			appenders do not include location information by default.
 			</p><p>
-			You can override the default behaviour in your logger 
-			or asynchronous appender configuration 
+			You can override the default behaviour in your logger
+			or asynchronous appender configuration
 			by specifying
 			<tt>includeLocation="true"</tt>.
 			</p>



Mime
View raw message