logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1592242 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/ log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ sr...
Date Sat, 03 May 2014 16:28:29 GMT
Author: rpopma
Date: Sat May  3 16:28:29 2014
New Revision: 1592242

URL: http://svn.apache.org/r1592242
Log:
LOG4J2-629 Use Clock to generate all log event timestamps, not just for Async Loggers

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
    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/impl/Log4jLogEventTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java?rev=1592242&r1=1592241&r2=1592242&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
Sat May  3 16:28:29 2014
@@ -197,6 +197,8 @@ public class PatternProcessor {
      * @param obj object to be evaluated in formatting, may not be null.
      */
     public final void formatFileName(final StrSubstitutor subst, final StringBuilder buf,
final Object obj) {
+        // LOG4J2-628: we deliberately use System time, not the log4j.Clock time
+        // for creating the file name of rolled-over files. 
         final long time = prevFileTime == 0 ? System.currentTimeMillis() : prevFileTime;
         formatFileName(buf, new Date(time), obj);
         LogEvent event = new Log4jLogEvent(time);

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=1592242&r1=1592241&r2=1592242&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 May  3 16:28:29 2014
@@ -29,6 +29,8 @@ import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.helpers.Clock;
+import org.apache.logging.log4j.core.helpers.ClockFactory;
 import org.apache.logging.log4j.message.LoggerNameAwareMessage;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.TimestampMessage;
@@ -39,6 +41,7 @@ import org.apache.logging.log4j.message.
 public class Log4jLogEvent implements LogEvent {
 
     private static final long serialVersionUID = -1351367343806656055L;
+    private static final Clock clock = ClockFactory.getClock();
     private final String fqcnOfLogger;
     private final Marker marker;
     private final Level level;
@@ -89,7 +92,7 @@ public class Log4jLogEvent implements Lo
         this(loggerName, marker, fqcn, level, message, t,
             createMap(properties),
             ThreadContext.getDepth() == 0 ? null : ThreadContext.cloneStack(), null,
-            null, System.currentTimeMillis());
+            null, clock.currentTimeMillis()); // LOG4J2-628 use log4j.Clock for timestamps
     }
 
     /**

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java?rev=1592242&r1=1592241&r2=1592242&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/Log4jLogEventTest.java
Sat May  3 16:28:29 2014
@@ -25,11 +25,36 @@ import java.io.ObjectOutputStream;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.helpers.Clock;
+import org.apache.logging.log4j.core.helpers.ClockFactory;
 import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class Log4jLogEventTest {
     
+    /** Helper class */
+    public static class FixedTimeClock implements Clock {
+        public static final long FIXED_TIME = 1234567890L;
+        /* (non-Javadoc)
+         * @see org.apache.logging.log4j.core.helpers.Clock#currentTimeMillis()
+         */
+        @Override
+        public long currentTimeMillis() {
+            return FIXED_TIME;
+        }        
+    }
+    @BeforeClass
+    public static void beforeClass() {
+        System.setProperty(ClockFactory.PROPERTY_NAME, FixedTimeClock.class.getName());
+    }
+    
+    @AfterClass
+    public static void afterClass() {
+        System.clearProperty(ClockFactory.PROPERTY_NAME);
+    }
+    
     @Test
     public void testJavaIoSerializable() throws Exception {
         final Log4jLogEvent evt = new Log4jLogEvent("some.test", null, "",
@@ -68,4 +93,14 @@ public class Log4jLogEventTest {
         assertEquals(Level.OFF, evt.getLevel());
     }
 
+    @Test
+    public void testTimestampGeneratedByClock() {
+        final Marker marker = null;
+        final Throwable t = null;
+        final Level NULL_LEVEL = null;
+        final Log4jLogEvent evt = new Log4jLogEvent("some.test", marker, "",
+                NULL_LEVEL, new SimpleMessage("abc"), t);
+        assertEquals(FixedTimeClock.FIXED_TIME, evt.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=1592242&r1=1592241&r2=1592242&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat May  3 16:28:29 2014
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-rc2" date="2014-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-629" dev="rpopma" type="fix">
+        Use Clock to generate all log event timestamps, not just for Async Loggers.
+      </action>
       <action issue="LOG4J2-629" dev="rpopma" type="add">
           Document the system properties used in Log4J 2.
       </action>



Mime
View raw message