logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1403125 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java src/changes/changes.xml
Date Sun, 28 Oct 2012 23:24:41 GMT
Author: rgoers
Date: Sun Oct 28 23:24:41 2012
New Revision: 1403125

URL: http://svn.apache.org/viewvc?rev=1403125&view=rev
Log:
Fix LOG4J2-103 - The LogEvent was wrapping a ThrowableProxy with another ThrowableProxy when
deserializing.

Added:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java?rev=1403125&r1=1403124&r2=1403125&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
Sun Oct 28 23:24:41 2012
@@ -103,7 +103,7 @@ public class Log4jLogEvent implements Lo
         this.fqcnOfLogger = fqcn;
         this.level = level;
         this.message = message;
-        this.throwable = t == null ? null : new ThrowableProxy(t);
+        this.throwable = (t == null ? null : (t instanceof ThrowableProxy ? (ThrowableProxy)t
: new ThrowableProxy(t)));
         this.mdc = mdc;
         this.ndc = ndc;
         this.timestamp = message instanceof TimestampMessage ? ((TimestampMessage) message).getTimestamp()
: timestamp;

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java?rev=1403125&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
(added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
Sun Oct 28 23:24:41 2012
@@ -0,0 +1,134 @@
+package org.apache.logging.log4j.core.appender.rewrite;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.MarkerManager;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.rewrite.MapRewritePolicy;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.ThrowableProxy;
+import org.apache.logging.log4j.message.MapMessage;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class MapRewritePolicyTest {
+	private static Map<String, String> map = new HashMap<String, String>();
+	private static KeyValuePair[] rewrite;
+	private static LogEvent logEvent0, logEvent1, logEvent2, logEvent3;
+
+	@BeforeClass
+	public static void setupClass() {
+		map.put("test1", "one");
+		map.put("test2", "two");
+		logEvent0 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
+        new SimpleMessage("Test"), new RuntimeException("test"), map, null, "none",
+        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest",
28), 2);
+		logEvent1 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
+        new MapMessage(map), null, map, null, "none",
+        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest",
29), 2);
+		logEvent2 = new Log4jLogEvent("test", MarkerManager.getMarker("test"), "MapRewritePolicyTest.setupClass()",
+        Level.TRACE, new StructuredDataMessage("test", "Nothing", "test", map), new RuntimeException("test"),
null,
+        new ThreadContext.ImmutableStack(map.values()), "none", new StackTraceElement("MapRewritePolicyTest",
+        "setupClass", "MapRewritePolicyTest", 30), 20000000);
+		logEvent3 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ALL,
new MapMessage(map),
+        null, map, new ThreadContext.ImmutableStack(map.values()), null, new StackTraceElement("MapRewritePolicyTest",
+        "setupClass", "MapRewritePolicyTest", 31), Long.MAX_VALUE);
+		rewrite = new KeyValuePair[] {new KeyValuePair("test2", "2"), new KeyValuePair("test3",
"three")};
+	}
+
+	@Test
+	public void addTest() {
+		MapRewritePolicy addPolicy = MapRewritePolicy.createPolicy("Add", rewrite);
+		LogEvent rewritten = addPolicy.rewrite(logEvent0);
+		compareLogEvents(logEvent0, rewritten);
+		Assert.assertEquals("Simple log message changed", logEvent0.getMessage(), rewritten.getMessage());
+
+		rewritten = addPolicy.rewrite(logEvent1);
+		compareLogEvents(logEvent1, rewritten);
+		checkAdded(((MapMessage)rewritten.getMessage()).getData());
+
+		rewritten = addPolicy.rewrite(logEvent2);
+		compareLogEvents(logEvent2, rewritten);
+		checkAdded(((MapMessage)rewritten.getMessage()).getData());
+
+		rewritten = addPolicy.rewrite(logEvent3);
+		compareLogEvents(logEvent3, rewritten);
+		checkAdded(((MapMessage)rewritten.getMessage()).getData());
+	}
+
+	@Test
+	public void updateTest() {
+		MapRewritePolicy updatePolicy = MapRewritePolicy.createPolicy("Update", rewrite);
+		LogEvent rewritten = updatePolicy.rewrite(logEvent0);
+		compareLogEvents(logEvent0, rewritten);
+		Assert.assertEquals("Simple log message changed", logEvent0.getMessage(), rewritten.getMessage());
+
+		rewritten = updatePolicy.rewrite(logEvent1);
+		compareLogEvents(logEvent1, rewritten);
+		checkUpdated(((MapMessage)rewritten.getMessage()).getData());
+
+		rewritten = updatePolicy.rewrite(logEvent2);
+		compareLogEvents(logEvent2, rewritten);
+		checkUpdated(((MapMessage)rewritten.getMessage()).getData());
+
+		rewritten = updatePolicy.rewrite(logEvent3);
+		compareLogEvents(logEvent3, rewritten);
+		checkUpdated(((MapMessage)rewritten.getMessage()).getData());
+	}
+
+	@Test
+	public void defaultIsAdd() {
+		MapRewritePolicy addPolicy = MapRewritePolicy.createPolicy(null, rewrite);
+		LogEvent rewritten = addPolicy.rewrite(logEvent0);
+		compareLogEvents(logEvent0, rewritten);
+		Assert.assertEquals("Simple log message changed", logEvent0.getMessage(), rewritten.getMessage());
+
+		rewritten = addPolicy.rewrite(logEvent1);
+		compareLogEvents(logEvent1, rewritten);
+		checkAdded(((MapMessage)rewritten.getMessage()).getData());
+
+		rewritten = addPolicy.rewrite(logEvent2);
+		compareLogEvents(logEvent2, rewritten);
+		checkAdded(((MapMessage)rewritten.getMessage()).getData());
+
+		rewritten = addPolicy.rewrite(logEvent3);
+		compareLogEvents(logEvent3, rewritten);
+		checkAdded(((MapMessage)rewritten.getMessage()).getData());
+	}
+
+	private void checkAdded(Map<String, String> addedMap) {
+		Assert.assertEquals("unwanted entry change", "one", addedMap.get("test1"));
+		Assert.assertEquals("existing entry not updated", "2", addedMap.get("test2"));
+		Assert.assertEquals("new entry not added", "three", addedMap.get("test3"));
+		Assert.assertEquals("wrong size", 3, addedMap.size());
+	}
+
+	private void checkUpdated(Map<String, String> updatedMap) {
+		Assert.assertEquals("unwanted entry change", "one", updatedMap.get("test1"));
+		Assert.assertEquals("existing entry not updated", "2", updatedMap.get("test2"));
+		Assert.assertEquals("wrong size", 2, updatedMap.size());
+	}
+
+	private void compareLogEvents(LogEvent orig, LogEvent changed) {
+		// Ensure that everything but the Mapped Data is still the same
+		Assert.assertEquals("LoggerName changed", orig.getLoggerName(), changed.getLoggerName());
+		Assert.assertEquals("Marker changed", orig.getMarker(), changed.getMarker());
+		Assert.assertEquals("FQCN changed", orig.getFQCN(), changed.getFQCN());
+		Assert.assertEquals("Level changed", orig.getLevel(), changed.getLevel());
+		Assert.assertEquals("Thrown changed", (orig.getThrown() == null ? null : ((ThrowableProxy)orig.getThrown()).getExtendedStackTrace()),
+				(changed.getThrown() == null ? null : ((ThrowableProxy)changed.getThrown()).getExtendedStackTrace()));
+		Assert.assertEquals("ContextMap changed", orig.getContextMap(), changed.getContextMap());
+		Assert.assertEquals("ContextStack changed", orig.getContextStack(), changed.getContextStack());
+		Assert.assertEquals("ThreadName changed", orig.getThreadName(), changed.getThreadName());
+		Assert.assertEquals("Source changed", orig.getSource(), changed.getSource());
+		Assert.assertEquals("Millis changed", orig.getMillis(), changed.getMillis());
+	}
+}

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1403125&r1=1403124&r2=1403125&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Oct 28 23:24:41 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta3" date="TBD" description= "Bug fixes and enhancements">
+      <action issue="LOG4J2-103" dev="rgoers" type="fix" due-to="Das Archive">
+        The LogEvent was wrapping a ThrowableProxy with another ThrowableProxy when deserializing.
+      </action>
       <action dev="rgoers" type="update">
         Created combined jar to combine API and Core contents for users who only want the
Log4j implementation.
       </action>



Mime
View raw message