You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2012/12/29 19:40:53 UTC
svn commit: r1426803 - 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/main/java/org/apache/logging/log4j/core/pattern/
core/src/test/java/org/...
Author: rgoers
Date: Sat Dec 29 18:40:53 2012
New Revision: 1426803
URL: http://svn.apache.org/viewvc?rev=1426803&view=rev
Log:
LOG4J2-136 - Allow newlines to be escaped in Syslog and RFC5424 layouts. Allow Throwables to be included in the output from 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/PatternLayout.java
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.java
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.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/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.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/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=1426803&r1=1426802&r2=1426803&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 Sat Dec 29 18:40:53 2012
@@ -89,6 +89,7 @@ public class SyslogAppender extends Sock
@PluginAttr("includeMDC") final String includeMDC,
@PluginAttr("mdcId") final String mdcId,
@PluginAttr("newLine") final String includeNL,
+ @PluginAttr("newLineEscape") final String escapeNL,
@PluginAttr("appName") final String appName,
@PluginAttr("messageId") final String msgId,
@PluginAttr("mdcExcludes") final String excludes,
@@ -97,7 +98,8 @@ public class SyslogAppender extends Sock
@PluginAttr("format") final String format,
@PluginElement("filters") final Filter filter,
@PluginConfiguration final Configuration config,
- @PluginAttr("charset") final String charset) {
+ @PluginAttr("charset") final String charset,
+ @PluginAttr("exceptionPattern") final String exceptionPattern) {
final boolean isFlush = immediateFlush == null ? true : Boolean.valueOf(immediateFlush);
final boolean handleExceptions = suppress == null ? true : Boolean.valueOf(suppress);
@@ -112,9 +114,9 @@ public class SyslogAppender extends Sock
}
}
final Layout layout = (RFC5424.equalsIgnoreCase(format)) ?
- RFC5424Layout.createLayout(facility, id, ein, includeMDC, mdcId, includeNL, appName, msgId,
- excludes, includes, required, charset, config) :
- SyslogLayout.createLayout(facility, includeNL, charset);
+ RFC5424Layout.createLayout(facility, id, ein, includeMDC, mdcId, includeNL, escapeNL, appName,
+ msgId, excludes, includes, required, charset, exceptionPattern, config) :
+ SyslogLayout.createLayout(facility, includeNL, escapeNL, charset);
if (name == null) {
LOGGER.error("No name provided for SyslogAppender");
@@ -127,6 +129,4 @@ public class SyslogAppender extends Sock
return new SyslogAppender(name, layout, filter, handleExceptions, isFlush, manager);
}
-
-
}
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java?rev=1426803&r1=1426802&r2=1426803&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java Sat Dec 29 18:40:53 2012
@@ -68,7 +68,7 @@ public final class PatternLayout extends
public static final String SIMPLE_CONVERSION_PATTERN =
"%d [%t] %p %c - %m%n";
- private static final String KEY = "Converter";
+ public static final String KEY = "Converter";
/**
* Initial converter for pattern.
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=1426803&r1=1426802&r2=1426803&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 Sat Dec 29 18:40:53 2012
@@ -26,6 +26,10 @@ import org.apache.logging.log4j.core.con
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.PatternFormatter;
+import org.apache.logging.log4j.core.pattern.PatternParser;
+import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.StructuredDataId;
import org.apache.logging.log4j.message.StructuredDataMessage;
@@ -43,6 +47,8 @@ import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
@@ -59,6 +65,10 @@ public final class RFC5424Layout extends
* The default event id.
*/
public static final String DEFAULT_ID = "Audit";
+ /**
+ * Match newlines in a platform-independent manner
+ */
+ public static final Pattern NEWLINE_PATTERN = Pattern.compile("\\r?\\n");
private static final String DEFAULT_MDCID = "mdc";
private static final int TWO_DIGITS = 10;
@@ -81,20 +91,28 @@ public final class RFC5424Layout extends
private final ListChecker checker;
private final ListChecker noopChecker = new NoopChecker();
private final boolean includeNewLine;
+ private final String escapeNewLine;
private long lastTimestamp = -1;
private String timestamppStr;
+ private static final String COMPONENT_KEY = "RFC5424-Converter";
+ private static final String DEFAULT_CONVERSION_PATTERN = "%xEx";
+ private List<PatternFormatter> formatters;
- private RFC5424Layout(final Configuration config, final Facility facility, final String id, final int ein, final boolean includeMDC,
- final boolean includeNL, final String mdcId, final String appName, final String messageId, final String excludes,
- final String includes, final String required, final Charset charset) {
+ 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 appName, final String messageId, final String excludes, final String includes,
+ final String required, final Charset charset, final String exceptionPattern) {
super(charset);
+ final PatternParser parser = createPatternParser(config);
+ formatters = exceptionPattern == null ? null : parser.parse(exceptionPattern, false);
this.facility = facility;
this.defaultId = id == null ? DEFAULT_ID : id;
this.enterpriseNumber = ein;
this.includeMDC = includeMDC;
this.includeNewLine = includeNL;
+ this.escapeNewLine = escapeNL == null ? null : Matcher.quoteReplacement(escapeNL);
this.mdcId = mdcId;
this.appName = appName;
this.messageId = messageId;
@@ -148,6 +166,25 @@ public final class RFC5424Layout extends
}
/**
+ * Create a PatternParser.
+ * @param config The Configuration.
+ * @return The PatternParser.
+ */
+ public static PatternParser createPatternParser(final Configuration config) {
+ if (config == null) {
+ return new PatternParser(config, PatternLayout.KEY, LogEventPatternConverter.class,
+ ThrowablePatternConverter.class);
+ }
+ PatternParser parser = (PatternParser) config.getComponent(COMPONENT_KEY);
+ if (parser == null) {
+ parser = new PatternParser(config, PatternLayout.KEY, ThrowablePatternConverter.class);
+ config.addComponent(COMPONENT_KEY, parser);
+ parser = (PatternParser) config.getComponent(COMPONENT_KEY);
+ }
+ return parser;
+ }
+
+ /**
* Formats a {@link org.apache.logging.log4j.core.LogEvent} in conformance with the RFC 5424 Syslog specification.
*
* @param event The LogEvent.
@@ -205,11 +242,18 @@ public final class RFC5424Layout extends
formatStructuredElement(mdcSDID, event.getContextMap(), buf, checker);
}
if (text != null && text.length() > 0) {
- buf.append(" ").append(text);
+ buf.append(" ").append(escapeNewlines(text, escapeNewLine));
}
} else {
buf.append("- ");
- buf.append(msg.getFormattedMessage());
+ buf.append(escapeNewlines(msg.getFormattedMessage(), escapeNewLine));
+ }
+ if (formatters != null && event.getThrown() != null) {
+ StringBuilder exception = new StringBuilder("\n");
+ for (PatternFormatter formatter : formatters) {
+ formatter.format(event, exception);
+ }
+ buf.append(escapeNewlines(exception.toString(), escapeNewLine));
}
if (includeNewLine) {
buf.append("\n");
@@ -217,6 +261,14 @@ public final class RFC5424Layout extends
return buf.toString();
}
+ private String escapeNewlines(String text, String escapeNewLine)
+ {
+ if(null == escapeNewLine) {
+ return text;
+ }
+ return NEWLINE_PATTERN.matcher(text).replaceAll(escapeNewLine);
+ }
+
protected String getProcId() {
return "-";
}
@@ -398,12 +450,13 @@ public final class RFC5424Layout extends
* record. Defaults to "true:.
* @param mdcId The id to use for the MDC Structured Data Element.
* @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 charset The character set.
+ * @param charsetName The character set.
* @param config The Configuration. Some Converters require access to the Interpolator.
* @return An RFC5424Layout.
*/
@@ -414,21 +467,27 @@ public final class RFC5424Layout extends
@PluginAttr("includeMDC") final String includeMDC,
@PluginAttr("mdcId") String mdcId,
@PluginAttr("newLine") final String includeNL,
+ @PluginAttr("newLineEscape") final String escapeNL,
@PluginAttr("appName") final String appName,
@PluginAttr("messageId") final String msgId,
@PluginAttr("mdcExcludes") final String excludes,
@PluginAttr("mdcIncludes") String includes,
@PluginAttr("mdcRequired") final String required,
- @PluginAttr("charset") final String charset,
+ @PluginAttr("charset") final String charsetName,
+ @PluginAttr("exceptionPattern") final String exceptionPattern,
@PluginConfiguration final Configuration config) {
- Charset c = Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset();
- if (charset != null) {
- if (Charset.isSupported(charset)) {
- c = Charset.forName(charset);
+ Charset charset = null;
+ if (charsetName != null) {
+ if (Charset.isSupported(charsetName)) {
+ charset = Charset.forName(charsetName);
} else {
- LOGGER.error("Charset " + charset + " is not supported for layout, using " + c.displayName());
+ LOGGER.error("Charset " + charsetName + " is not supported for layout, using " + charset.displayName());
}
}
+ if(charset == null) {
+ charset = Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset();
+ }
+
if (includes != null && excludes != null) {
LOGGER.error("mdcIncludes and mdcExcludes are mutually exclusive. Includes wil be ignored");
includes = null;
@@ -441,7 +500,7 @@ public final class RFC5424Layout extends
mdcId = DEFAULT_MDCID;
}
- return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine, mdcId, appName, msgId,
- excludes, includes, required, c);
+ return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine, escapeNL, mdcId, appName, msgId,
+ excludes, includes, required, charset, exceptionPattern);
}
}
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java?rev=1426803&r1=1426802&r2=1426803&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/SyslogLayout.java Sat Dec 29 18:40:53 2012
@@ -29,6 +29,8 @@ import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
@@ -36,9 +38,14 @@ import java.util.Locale;
*/
@Plugin(name = "SyslogLayout", type = "Core", elementType = "layout", printObject = true)
public class SyslogLayout extends AbstractStringLayout {
+ /**
+ * Match newlines in a platform-independent manner
+ */
+ public static final Pattern NEWLINE_PATTERN = Pattern.compile("\\r?\\n");
private final Facility facility;
private final boolean includeNewLine;
+ private final String escapeNewLine;
/**
* Date format used if header = true.
@@ -50,10 +57,12 @@ public class SyslogLayout extends Abstra
private final String localHostname = getLocalHostname();
- protected SyslogLayout(final Facility facility, final boolean includeNL, final Charset c) {
+
+ protected SyslogLayout(final Facility facility, final boolean includeNL, final String escapeNL, final Charset c) {
super(c);
this.facility = facility;
this.includeNewLine = includeNL;
+ this.escapeNewLine = escapeNL == null ? null : Matcher.quoteReplacement(escapeNL);
}
/**
@@ -72,7 +81,14 @@ public class SyslogLayout extends Abstra
buf.append(" ");
buf.append(localHostname);
buf.append(" ");
- buf.append(event.getMessage().getFormattedMessage());
+
+ String message = event.getMessage().getFormattedMessage();
+ if(null != escapeNewLine)
+ {
+ message = NEWLINE_PATTERN.matcher(message).replaceAll(escapeNewLine);
+ }
+ buf.append(message);
+
if (includeNewLine) {
buf.append("\n");
}
@@ -115,6 +131,7 @@ public class SyslogLayout extends Abstra
@PluginFactory
public static SyslogLayout createLayout(@PluginAttr("facility") final String facility,
@PluginAttr("newLine") final String includeNL,
+ @PluginAttr("newLineEscape") final String escapeNL,
@PluginAttr("charset") final String charset) {
Charset c = Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset();
@@ -127,6 +144,6 @@ public class SyslogLayout extends Abstra
}
final boolean includeNewLine = includeNL == null ? false : Boolean.valueOf(includeNL);
final Facility f = Facility.toFacility(facility, Facility.LOCAL0);
- return new SyslogLayout(f, includeNewLine, c);
+ return new SyslogLayout(f, includeNewLine, escapeNL, c);
}
}
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java?rev=1426803&r1=1426802&r2=1426803&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java Sat Dec 29 18:40:53 2012
@@ -88,7 +88,7 @@ public final class PatternParser {
* @param converterKey The type of converters that will be used.
*/
public PatternParser(final String converterKey) {
- this(null, converterKey, null);
+ this(null, converterKey, null, null);
}
/**
@@ -98,6 +98,18 @@ public final class PatternParser {
* @param expected The expected base Class of each Converter.
*/
public PatternParser(final Configuration config, final String converterKey, final Class<?> expected) {
+ this(config, converterKey, expected, null);
+ }
+
+ /**
+ * Constructor.
+ * @param config The current Configuration.
+ * @param converterKey The key to lookup the converters.
+ * @param expected The expected base Class of each Converter.
+ * @param filterClass Filter the returned plugins after calling the plugin manager.
+ */
+ public PatternParser(final Configuration config, final String converterKey, final Class<?> expected,
+ final Class<?> filterClass) {
this.config = config;
final PluginManager manager = new PluginManager(converterKey, expected);
manager.collectPlugins();
@@ -107,6 +119,9 @@ public final class PatternParser {
for (final PluginType type : plugins.values()) {
try {
final Class<PatternConverter> clazz = type.getPluginClass();
+ if (filterClass != null && !filterClass.isAssignableFrom(clazz)) {
+ continue;
+ }
final ConverterKeys keys = clazz.getAnnotation(ConverterKeys.class);
if (keys != null) {
for (final String key : keys.value()) {
@@ -120,6 +135,7 @@ public final class PatternParser {
converterRules = converters;
}
+
public List<PatternFormatter> parse(final String pattern) {
return parse(pattern, false);
}
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=1426803&r1=1426802&r2=1426803&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 Sat Dec 29 18:40:53 2012
@@ -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", "TestApp", "Test", null, "ipAddress,loginId", null, format, null,
- null, null);
+ "18060", "true", "RequestContext", "true", null, "TestApp", "Test", null, "ipAddress,loginId", null, format, 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=1426803&r1=1426802&r2=1426803&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 Sat Dec 29 18:40:53 2012
@@ -20,9 +20,11 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.BasicConfigurationFactory;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
@@ -66,19 +68,19 @@ public class RFC5424LayoutTest {
ConfigurationFactory.removeConfigurationFactory(cf);
}
-
-
-
/**
* Test case for MDC conversion pattern.
*/
@Test
public void testLayout() throws Exception {
-
+ for (Appender appender : root.getAppenders().values()) {
+ root.removeAppender(appender);
+ }
// set up appender
final RFC5424Layout layout = RFC5424Layout.createLayout("Local0", "Event", "3692", "true", "RequestContext",
- "true", "ATM", null, "key1, key2, locale", null, "loginId", 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();
// set appender on root and set level to debug
@@ -122,7 +124,7 @@ public class RFC5424LayoutTest {
list = appender.getMessages();
assertTrue("No messages expected, found " + list.size(), list.size() == 0);
} finally {
-
+ root.removeAppender(appender);
ThreadContext.clear();
appender.stop();
@@ -130,4 +132,43 @@ public class RFC5424LayoutTest {
}
+ /**
+ * Test case for MDC conversion pattern.
+ */
+ @Test
+ public void testException() throws Exception {
+ for (Appender appender : root.getAppenders().values()) {
+ root.removeAppender(appender);
+ }
+ // set up appender
+ final RFC5424Layout layout = RFC5424Layout.createLayout("Local0", "Event", "3692", "true", "RequestContext",
+ "true", null, "ATM", null, "key1, key2, locale", null, "loginId", null, "%xEx", 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);
+
+ ThreadContext.put("loginId", "JohnDoe");
+
+ // output starting message
+ root.debug("starting mdc pattern test", new IllegalArgumentException("Test"));
+
+ try {
+
+ List<String> list = appender.getMessages();
+
+ assertTrue("Not enough list entries", list.size() > 1);
+ assertTrue("No Exception", list.get(1).contains("IllegalArgumentException"));
+
+ appender.clear();
+ } finally {
+ root.removeAppender(appender);
+ ThreadContext.clear();
+
+ appender.stop();
+ }
+ }
+
}
Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java?rev=1426803&r1=1426802&r2=1426803&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java (original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/SyslogLayoutTest.java Sat Dec 29 18:40:53 2012
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.BasicConfigurationFactory;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
@@ -71,9 +72,11 @@ public class SyslogLayoutTest {
*/
@Test
public void testLayout() throws Exception {
-
+ for (Appender appender : root.getAppenders().values()) {
+ root.removeAppender(appender);
+ }
// set up appender
- final SyslogLayout layout = SyslogLayout.createLayout("Local0", "true", null);
+ final SyslogLayout layout = SyslogLayout.createLayout("Local0", "true", null, null);
//ConsoleAppender appender = new ConsoleAppender("Console", layout);
final ListAppender appender = new ListAppender("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=1426803&r1=1426802&r2=1426803&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 Sat Dec 29 18:40:53 2012
@@ -153,7 +153,7 @@ public final class FlumeAppender extends
if (layout == null) {
layout = RFC5424Layout.createLayout(null, null, null, "True", null, null, null, null, excludes,
- includes, required, null, null);
+ includes, required, null, null, null, null);
}
if (name == null) {
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1426803&r1=1426802&r2=1426803&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Dec 29 18:40:53 2012
@@ -23,6 +23,10 @@
<body>
<release version="2.0-beta4" date="TBD" description="Bug fixes and enhancements">
+ <action issue="LOG4J2-136" dev="rgoers" type="update" due-to="Scott Severtson">
+ Allow newlines to be escaped in Syslog and RFC5424 layouts. Allow Throwables to be included in
+ the output from RFC5424Layout.
+ </action>
<action issue="LOG4J2-131" dev="rgoers" type="add" due-to="Scott Severtson">
Add SMTPAppender.
</action>
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=1426803&r1=1426802&r2=1426803&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 Sat Dec 29 18:40:53 2012
@@ -988,6 +988,13 @@ at org.apache.logging.log4j.core.pattern
<a href="http://tools.ietf.org/html/rfc5424#section-7.2.2">RFC 5424</a></td>
</tr>
<tr>
+ <td>exceptionPattern</td>
+ <td>String</td>
+ <td>One of the conversion specifiers from PatternLayout that defines which ThrowablePatternConverter
+ to use to format exceptions. Any of the options that are valid for those specifiers may be included.
+ The default is to not include the Throwable from the event, if any, in the output.</td>
+ </tr>
+ <tr>
<td>facility</td>
<td>String</td>
<td>The facility is used to try to classify the message. The facility option must be set to one of
@@ -1057,6 +1064,11 @@ at org.apache.logging.log4j.core.pattern
<td>boolean</td>
<td>If true, a newline will be appended to the end of the syslog record. The default is false.</td>
</tr>
+ <tr>
+ <td>newLineEscape</td>
+ <td>String</td>
+ <td>String that should be used to replace newlines within the message text.</td>
+ </tr>
<caption align="top">RFC5424Layout Parameters</caption>
</table>
</subsection>
@@ -1097,7 +1109,12 @@ at org.apache.logging.log4j.core.pattern
<td>boolean</td>
<td>If true, a newline will be appended to the end of the syslog record. The default is false.</td>
</tr>
- <caption align="top">SyslogLayout Parameters</caption>
+ <tr>
+ <td>newLineEscape</td>
+ <td>String</td>
+ <td>String that should be used to replace newlines within the message text.</td>
+ </tr>
+ <caption align="top">SyslogLayout Parameters</caption>
</table>
</subsection>
<a name="XMLLayout"/>