You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/04/18 13:37:51 UTC

[05/50] logging-log4j2 git commit: LOG4J2-1334 ReusableLogEventFactory various fixes

LOG4J2-1334 ReusableLogEventFactory various fixes


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/dc9b6afe
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/dc9b6afe
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/dc9b6afe

Branch: refs/heads/LOG4J2-1365
Commit: dc9b6afe0c3b46d57f88671802134574d6b530fa
Parents: adcdfc0
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:39:22 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:39:22 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/ReusableLogEventFactory.java       | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dc9b6afe/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
index 190b27a..2912d91 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
@@ -24,11 +24,13 @@ import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.util.Clock;
 import org.apache.logging.log4j.core.util.ClockFactory;
 import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.TimestampMessage;
 
 import java.util.List;
 
 /**
  * Garbage-free LogEventFactory that reuses a single mutable log event.
+ * @since 2.6
  */
 public class ReusableLogEventFactory implements LogEventFactory {
 
@@ -41,14 +43,14 @@ public class ReusableLogEventFactory implements LogEventFactory {
      * @param marker An optional Marker.
      * @param fqcn The fully qualified class name of the caller.
      * @param level The event Level.
-     * @param data The Message.
+     * @param message The Message.
      * @param properties Properties to be added to the log event.
      * @param t An optional Throwable.
      * @return The LogEvent.
      */
     @Override
     public LogEvent createEvent(final String loggerName, final Marker marker,
-                                final String fqcn, final Level level, final Message data,
+                                final String fqcn, final Level level, final Message message,
                                 final List<Property> properties, final Throwable t) {
         MutableLogEvent result = mutableLogEventThreadLocal.get();
         if (result == null) {
@@ -58,16 +60,19 @@ public class ReusableLogEventFactory implements LogEventFactory {
             result.setThreadPriority(Thread.currentThread().getPriority());
             mutableLogEventThreadLocal.set(result);
         }
+        result.clear();
 
         result.setLoggerName(loggerName);
         result.setMarker(marker);
         result.setLoggerFqcn(fqcn);
         result.setLevel(level == null ? Level.OFF : level);
-        result.setMessage(data);
+        result.setMessage(message);
         result.setThrown(t);
         result.setContextMap(Log4jLogEvent.createMap(properties));
         result.setContextStack(ThreadContext.getDepth() == 0 ? null : ThreadContext.cloneStack());// mutable copy
-        result.setTimeMillis(CLOCK.currentTimeMillis());
+        result.setTimeMillis(message instanceof TimestampMessage
+                ? ((TimestampMessage) message).getTimestamp()
+                : CLOCK.currentTimeMillis());
         result.setNanoTime(Log4jLogEvent.getNanoClock().nanoTime());
 
         // TODO