logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1601179 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/ log4j-core/src/test/java/org/apache/logging/log4j/ log4j-core/src/test/resources/ src/changes/
Date Sat, 07 Jun 2014 22:36:37 GMT
Author: rgoers
Date: Sat Jun  7 22:36:36 2014
New Revision: 1601179

URL: http://svn.apache.org/r1601179
Log:
LOG4J2-535 - Reset rollover time when size rollover is triggered.

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/rollover-test.xml
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/appender/rolling/SizeBasedTriggeringPolicy.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=1601179&r1=1601178&r2=1601179&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 Jun  7 22:36:36 2014
@@ -163,10 +163,14 @@ public class PatternProcessor {
         return debugGetNextTime(nextTime);
     }
 
+    public void updateTime() {
+        prevFileTime = nextFileTime;
+    }
+
     private long debugGetNextTime(long nextTime) {
         if (LOGGER.isTraceEnabled()) {
-            LOGGER.trace("PatternProcessor.getNextTime returning {}, nextFileTime={}, prevFileTime={},
freq={}", //
-                    format(nextTime), format(nextFileTime), format(prevFileTime), frequency);
+            LOGGER.trace("PatternProcessor.getNextTime returning {}, nextFileTime={}, prevFileTime={},
current={}, freq={}", //
+                    format(nextTime), format(nextFileTime), format(prevFileTime), format(System.currentTimeMillis()),
frequency);
         }
         return nextTime;
     }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/SizeBasedTriggeringPolicy.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/SizeBasedTriggeringPolicy.java?rev=1601179&r1=1601178&r2=1601179&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/SizeBasedTriggeringPolicy.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/SizeBasedTriggeringPolicy.java
Sat Jun  7 22:36:36 2014
@@ -92,7 +92,11 @@ public class SizeBasedTriggeringPolicy i
      */
     @Override
     public boolean isTriggeringEvent(final LogEvent event) {
-        return manager.getFileSize() > maxFileSize;
+        boolean triggered = manager.getFileSize() > maxFileSize;
+        if (triggered) {
+            manager.getPatternProcessor().updateTime();
+        }
+        return triggered;
     }
 
     @Override

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java?rev=1601179&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java
Sat Jun  7 22:36:36 2014
@@ -0,0 +1,25 @@
+package org.apache.logging.log4j;
+
+import org.apache.logging.log4j.core.config.Configurator;
+
+import java.io.File;
+
+/**
+ *
+ */
+public class LogRolloverTest {
+
+    private static final String CONFIG = "src/test/resources/rollover-test.xml";
+
+
+    public static void main(String[] args) throws Exception {
+        File file = new File(CONFIG);
+        Configurator.initialize("LogTest", LogRolloverTest.class.getClassLoader(), file.toURI());
+        Logger logger = LogManager.getLogger("TestLogger");
+
+        for (long i=0; ; i+=1) {
+            logger.debug("Sequence: " + i);
+            Thread.sleep(250);
+        }
+    }
+}

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/rollover-test.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/resources/rollover-test.xml?rev=1601179&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/resources/rollover-test.xml (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/resources/rollover-test.xml Sat Jun  7
22:36:36 2014
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="trace">
+    <Appenders>
+        <RollingFile name="Test" fileName="target/logs/test.log" filePattern="target/logs/test/$${date:yyyyMMddHHmm}/TEST-%d{yyyyMMddHHmm}-%i.log.gz">
+            <PatternLayout pattern="%d %p (%t) [%c] - %m%n"/>
+            <Policies>
+                <TimeBasedTriggeringPolicy />
+                <SizeBasedTriggeringPolicy size="1 KB"/>
+            </Policies>
+            <DefaultRolloverStrategy max="999999"/>
+        </RollingFile>
+    </Appenders>
+    <Loggers>
+        <Root level="debug">
+            <AppenderRef ref="Test"/>
+        </Root>
+    </Loggers>
+</Configuration>
\ No newline at end of file

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1601179&r1=1601178&r2=1601179&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Jun  7 22:36:36 2014
@@ -22,6 +22,9 @@
   </properties>
   <body>
     <release version="2.0-rc2" date="2014-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-535" dev="rgoers" type="fix">
+        Reset rollover time when size rollover is triggered.
+      </action>
       <action issue="LOG4J2-664" dev="mattsicker" type="fix">
         Moved plugin cache file to META-INF for OSGi compatibility.
       </action>



Mime
View raw message