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/11/13 18:23:42 UTC
svn commit: r1408842 - in /logging/log4j/log4j2/trunk:
core/src/main/java/org/apache/logging/log4j/core/layout/
flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/
flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/ src/changes/
Author: rgoers
Date: Tue Nov 13 17:23:41 2012
New Revision: 1408842
URL: http://svn.apache.org/viewvc?rev=1408842&view=rev
Log:
Fix LOG4J2-115 - ThreadContext Map elements with null values are now ignored when constructing a Flume event and in the RFC5424 Layout
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/RFC5424Layout.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
logging/log4j/log4j2/trunk/src/changes/changes.xml
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=1408842&r1=1408841&r2=1408842&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 Tue Nov 13 17:23:41 2012
@@ -370,7 +370,7 @@ public final class RFC5424Layout extends
{
SortedMap<String, String> sorted = new TreeMap<String, String>(map);
for (Map.Entry<String, String> entry : sorted.entrySet()) {
- if (checker.check(entry.getKey())) {
+ if (checker.check(entry.getKey()) && entry.getValue() != null) {
sb.append(" ");
sb.append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
}
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=1408842&r1=1408841&r2=1408842&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 Tue Nov 13 17:23:41 2012
@@ -143,7 +143,9 @@ public class FlumeEvent extends SimpleEv
protected void addContextData(String prefix, Map<String, String> fields, Map<String, String> context) {
for (Map.Entry<String, String> entry : context.entrySet()) {
- fields.put(prefix + entry.getKey(), entry.getValue());
+ if (entry.getKey() != null && entry.getValue() != null) {
+ fields.put(prefix + entry.getKey(), entry.getValue());
+ }
}
}
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=1408842&r1=1408841&r2=1408842&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 Tue Nov 13 17:23:41 2012
@@ -30,11 +30,14 @@ import org.apache.flume.conf.Configurabl
import org.apache.flume.lifecycle.LifecycleController;
import org.apache.flume.lifecycle.LifecycleState;
import org.apache.flume.source.AvroSource;
+import org.apache.logging.log4j.EventLogger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.message.StructuredDataMessage;
import org.apache.logging.log4j.status.StatusLogger;
import org.junit.After;
import org.junit.AfterClass;
@@ -50,6 +53,7 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.zip.GZIPInputStream;
/**
@@ -148,6 +152,43 @@ public class FlumeAppenderTest {
eventSource.stop();
}
+ @Test
+ public void testStructured() throws InterruptedException, IOException {
+ Agent[] agents = new Agent[] {Agent.createAgent("localhost", testPort)};
+ FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, "false", null, "100", "3", "avro",
+ "false", null, null, null, null, null, "true", "1", null, null, null);
+ avroAppender.start();
+ Logger eventLogger = (Logger) LogManager.getLogger("EventLogger");
+ Assert.assertNotNull(eventLogger);
+ eventLogger.addAppender(avroAppender);
+ eventLogger.setLevel(Level.ALL);
+
+ StructuredDataMessage msg = new StructuredDataMessage("Transer", "Success", "Audit");
+ msg.put("memo", "This is a memo");
+ msg.put("acct", "12345");
+ msg.put("amount", "100.00");
+ ThreadContext.put("id", UUID.randomUUID().toString());
+ ThreadContext.put("memo", null);
+ ThreadContext.put("test", "123");
+
+ EventLogger.logEvent(msg);
+
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+
+ Event event = channel.take();
+ Assert.assertNotNull(event);
+ Assert.assertTrue("Channel contained event, but not expected message",
+ getBody(event).endsWith("Success"));
+ transaction.commit();
+ transaction.close();
+
+ eventSource.stop();
+ eventLogger.removeAppender(avroAppender);
+ avroAppender.stop();
+ }
+
+
@Test
public void testMultiple() throws InterruptedException, IOException {
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1408842&r1=1408841&r2=1408842&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Nov 13 17:23:41 2012
@@ -23,6 +23,10 @@
<body>
<release version="2.0-beta4" date="TBD" description="Bug fixes and enhancements">
+ <action issue="LOG4J2-115" dev="rgoers" type="fix">
+ ThreadContext Map elements with null values are now ignored when constructing a Flume event and in the
+ RFC5424 Layout.
+ </action>
<action issue="LOG4J2-113" dev="rgoers" type="fix">
StructuredDataFilter createFilter was annotated with PluginAttr instead of PluginElement for the
KeyValuePairs.