[logback-dev] branch, master, updated. 043fe3b6471a4025911da4a78d28fc41cd775038

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Thu Nov 12 11:27:20 CET 2009


The branch, master has been updated
       via  043fe3b6471a4025911da4a78d28fc41cd775038 (commit)
      from  4cdca9f671ff8251e7775fee498a7331328ffa5b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=043fe3b6471a4025911da4a78d28fc41cd775038
http://github.com/ceki/logback/commit/043fe3b6471a4025911da4a78d28fc41cd775038

commit 043fe3b6471a4025911da4a78d28fc41cd775038
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Thu Nov 12 01:22:45 2009 +0100

    - minor refactoring in DefaultArchiver and SizeAndTimeBasedArchiveRemover
    
    - Adapted TimeBasedRollingWithArchiveRemovalTest so that
    dailySizeBasedRollover() no longer fails under certain circumstances,
    e.g. when in the last period no size-based rollover occuers. Also
    increased the number of ticks per period (more logging calls) and
    increased the triggering size (less size-based rollovers for faster
    test execution time)

diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
index 6640853..c18b53c 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
@@ -23,7 +23,7 @@ public class DefaultArchiveRemover implements ArchiveRemover {
 
   final FileNamePattern fileNamePattern;
   final RollingCalendar rc;
-  int periodOffset;
+  int periodOffsetForDeletionTarget;
   final boolean parentClean;
 
   public DefaultArchiveRemover(FileNamePattern fileNamePattern,
@@ -67,7 +67,7 @@ public class DefaultArchiveRemover implements ArchiveRemover {
   }
 
   public void clean(Date now) {
-    Date date2delete = rc.getRelativeDate(now, periodOffset);
+    Date date2delete = rc.getRelativeDate(now, periodOffsetForDeletionTarget);
     String filename = fileNamePattern.convert(date2delete);
     File file2Delete = new File(filename);
     if (file2Delete.exists() && file2Delete.isFile()) {
@@ -98,7 +98,7 @@ public class DefaultArchiveRemover implements ArchiveRemover {
   }
 
   public void setMaxHistory(int maxHistory) {
-    this.periodOffset = -maxHistory - 1;
+    this.periodOffsetForDeletionTarget = -maxHistory - 1;
   }
 
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
index a9cdfdc..c5efefd 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
@@ -145,9 +145,7 @@ public class FileNamePattern extends ContextAwareBase {
   }
 
   /**
-   * Given date, convert this instance to a  regular expression. A
-   * slashified regex, is a regex with naturally occurring forward slash
-   * characters replaced by back slashes.
+   * Given date, convert this instance to a  regular expression.
     */
   public String toRegex(Date date) {
     StringBuilder buf = new StringBuilder();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
index 66d7513..397ad9a 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SizeAndTimeBasedArchiveRemover.java
@@ -25,7 +25,7 @@ public class SizeAndTimeBasedArchiveRemover extends DefaultArchiveRemover {
 
   @Override
   public void clean(Date now) {
-    Date dateOfPeriodToClean = rc.getRelativeDate(now, periodOffset);
+    Date dateOfPeriodToClean = rc.getRelativeDate(now, periodOffsetForDeletionTarget);
 
     String regex = fileNamePattern.toRegex(dateOfPeriodToClean);
     String stemRegex = FileFilterUtil.afterLastSlash(regex);
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
index af4a068..2e2e27a 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemovalTest.java
@@ -104,7 +104,7 @@ public class TimeBasedRollingWithArchiveRemovalTest {
     slashCount = computeSlashCount(MONTHLY_CROLOLOG_DATE_PATTERN);
     int numPeriods = 40;
     int maxHistory = 2;
-    
+
     doRollover(randomOutputDir + "/%d{" + MONTHLY_CROLOLOG_DATE_PATTERN
         + "}/clean.txt.zip", MILLIS_IN_MONTH, maxHistory, numPeriods);
     int beginPeriod = Calendar.getInstance().get(Calendar.MONTH);
@@ -136,21 +136,25 @@ public class TimeBasedRollingWithArchiveRemovalTest {
   @Test
   public void dailySizeBasedRollover() throws Exception {
     SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
-    sizeAndTimeBasedFNATP.setMaxFileSize("10");
+    sizeAndTimeBasedFNATP.setMaxFileSize("10000");
     tbfnatp = sizeAndTimeBasedFNATP;
 
     slashCount = computeSlashCount(DAILY_DATE_PATTERN);
     doRollover(
         randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i.zip",
         MILLIS_IN_DAY, 5, 5 * 4);
+    
+    // make .zip optional so that if for one reason or another, no size-based
+    // rollover occurs on the last period, that the last period is still accounted
+    // for
     checkPatternCompliance(5 + 1 + slashCount,
-        "\\d{4}-\\d{2}-\\d{2}-clean.(\\d).zip");
+        "\\d{4}-\\d{2}-\\d{2}-clean.(\\d)(.zip)?");
   }
 
   @Test
   public void dailyChronologSizeBasedRollover() throws Exception {
     SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
-    sizeAndTimeBasedFNATP.setMaxFileSize("10");
+    sizeAndTimeBasedFNATP.setMaxFileSize("10000");
     tbfnatp = sizeAndTimeBasedFNATP;
 
     slashCount = 1;
@@ -180,19 +184,22 @@ public class TimeBasedRollingWithArchiveRemovalTest {
     rfa.setRollingPolicy(tbrp);
     rfa.start();
 
-    int ticksPerPeriod = 64;
+    // lots of ticks per period
+    int ticksPerPeriod = 512;
     long runLength = simulatedNumberOfPeriods * ticksPerPeriod;
 
-    for (long i = 0; i < runLength; i++) {
+    long i = 0;
+    for (; i < runLength; i++) {
       rfa
           .doAppend("Hello ----------------------------------------------------------"
               + i);
       tbrp.timeBasedTriggering.setCurrentTime(addTime(tbrp.timeBasedTriggering
           .getCurrentTime(), periodDurationInMillis / ticksPerPeriod));
 
-      if (tbrp.future != null) {
-        tbrp.future.get(200, TimeUnit.MILLISECONDS);
-      }
+    }
+    
+    if (tbrp.future != null && !tbrp.future.isDone()) {
+      tbrp.future.get(200, TimeUnit.MILLISECONDS);
     }
     rfa.stop();
   }
@@ -324,6 +331,9 @@ public class TimeBasedRollingWithArchiveRemovalTest {
     assertEquals(expectedClassCount, fileList.size());
   }
 
+  // reduce file names differing by index number into the same group
+  // for example, 2009-11-01-clean-0.zip, 2009-11-01-clean-1.zip and
+  // 2009-11-01-clean-2 are reduced into the same string (group)
   Set<String> groupByClass(List<File> fileList, String regex) {
     Pattern p = Pattern.compile(regex);
     Set<String> set = new HashSet<String>();
@@ -333,7 +343,8 @@ public class TimeBasedRollingWithArchiveRemovalTest {
       m.matches();
       int begin = m.start(1);
       int end = m.end(1);
-      set.add(n.substring(0, begin) + n.substring(end));
+      String reduced = n.substring(0, begin) + n.substring(end);
+      set.add(reduced);
     }
     return set;
   }

-----------------------------------------------------------------------

Summary of changes:
 .../core/rolling/helper/DefaultArchiveRemover.java |    6 ++--
 .../core/rolling/helper/FileNamePattern.java       |    4 +--
 .../helper/SizeAndTimeBasedArchiveRemover.java     |    2 +-
 .../TimeBasedRollingWithArchiveRemovalTest.java    |   31 +++++++++++++------
 4 files changed, 26 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list