logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1573123 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java src/changes/changes.xml
Date Sat, 01 Mar 2014 03:29:36 GMT
Author: rgoers
Date: Sat Mar  1 03:29:35 2014
New Revision: 1573123

URL: http://svn.apache.org/r1573123
Log:
LOG4J2-499 - Add equals and hashcode to Log4jLogEvent.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java?rev=1573123&r1=1573122&r2=1573123&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
Sat Mar  1 03:29:35 2014
@@ -396,6 +396,78 @@ public class Log4jLogEvent implements Lo
         return sb.toString();
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        Log4jLogEvent that = (Log4jLogEvent) o;
+
+        if (endOfBatch != that.endOfBatch) {
+            return false;
+        }
+        if (includeLocation != that.includeLocation) {
+            return false;
+        }
+        if (timestamp != that.timestamp) {
+            return false;
+        }
+        if (fqcnOfLogger != null ? !fqcnOfLogger.equals(that.fqcnOfLogger) : that.fqcnOfLogger
!= null) {
+            return false;
+        }
+        if (level != null ? !level.equals(that.level) : that.level != null) {
+            return false;
+        }
+        if (location != null ? !location.equals(that.location) : that.location != null) {
+            return false;
+        }
+        if (marker != null ? !marker.equals(that.marker) : that.marker != null) {
+            return false;
+        }
+        if (mdc != null ? !mdc.equals(that.mdc) : that.mdc != null) {
+            return false;
+        }
+        if (!message.equals(that.message)) {
+            return false;
+        }
+        if (!name.equals(that.name)) {
+            return false;
+        }
+        if (ndc != null ? !ndc.equals(that.ndc) : that.ndc != null) {
+            return false;
+        }
+        if (threadName != null ? !threadName.equals(that.threadName) : that.threadName !=
null) {
+            return false;
+        }
+        if (throwable != null ? !throwable.equals(that.throwable) : that.throwable != null)
{
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = fqcnOfLogger != null ? fqcnOfLogger.hashCode() : 0;
+        result = 31 * result + (marker != null ? marker.hashCode() : 0);
+        result = 31 * result + (level != null ? level.hashCode() : 0);
+        result = 31 * result + name.hashCode();
+        result = 31 * result + message.hashCode();
+        result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
+        result = 31 * result + (throwable != null ? throwable.hashCode() : 0);
+        result = 31 * result + (mdc != null ? mdc.hashCode() : 0);
+        result = 31 * result + (ndc != null ? ndc.hashCode() : 0);
+        result = 31 * result + (threadName != null ? threadName.hashCode() : 0);
+        result = 31 * result + (location != null ? location.hashCode() : 0);
+        result = 31 * result + (includeLocation ? 1 : 0);
+        result = 31 * result + (endOfBatch ? 1 : 0);
+        return result;
+    }
+
     /**
      * Proxy pattern used to serialize the LogEvent.
      */

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java?rev=1573123&r1=1573122&r2=1573123&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java
Sat Mar  1 03:29:35 2014
@@ -29,6 +29,8 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 /**
@@ -64,4 +66,15 @@ public class LogEventTest {
             fail("Exception processing event2");
         }
     }
+
+    public void testEquals() {
+        final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null, "org.apache.logging.log4j.core.Logger",
+            Level.INFO, new SimpleMessage("Hello, world!"), null);
+        final LogEvent event2 = new Log4jLogEvent(this.getClass().getName(), null, "org.apache.logging.log4j.core.Logger",
+            Level.INFO, new SimpleMessage("Hello, Apache!"), null);
+        final LogEvent event3 = new Log4jLogEvent(this.getClass().getName(), null, "org.apache.logging.log4j.core.Logger",
+            Level.INFO, new SimpleMessage("Hello, Apache!"), null);
+        assertNotEquals("Events should not be equal", event1, event2);
+        assertEquals("Events should be equal", event2, event3);
+    }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1573123&r1=1573122&r2=1573123&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Mar  1 03:29:35 2014
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-rc2?" date="2014-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-499" dev="rgoers"  type="fix">
+        Add equals and hashcode to Log4jLogEvent.
+      </action>
       <action issue="LOG4J2-410" dev="rgoers" type="update" due-to="Ivlin Zeng">
         SLf4JLogger is now Serializable.
       </action>



Mime
View raw message