[logback-dev] svn commit: r2401 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/rolling

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Jul 31 21:11:53 CEST 2009


Author: ceki
Date: Fri Jul 31 21:11:53 2009
New Revision: 2401

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java

Log:
Testing configuration file driven TimeBasedRolling

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java	Fri Jul 31 21:11:53 2009
@@ -1,8 +1,23 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2009, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
 package ch.qos.logback.core.rolling;
 
 import java.io.File;
 import java.util.Date;
 
+/**
+ * 
+ * @author Ceki Gülcü
+ *
+ * @param <E>
+ */
 public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
 
 
@@ -10,14 +25,12 @@
   @Override
   public void start() {
     super.start();
-    
     started = true;
   }
   
 
   public boolean isTriggeringEvent(File activeFile, final E event) {
     long time = getCurrentTime();
-
     if (time >= nextCheck) {
       Date dateOfElapsedPeriod = dateInCurrentPeriod;
       elapsedPeriodsFileName = tbrp.fileNamePatternWCS

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java	Fri Jul 31 21:11:53 2009
@@ -153,7 +153,7 @@
     return rollingPolicy;
   }
 
-  public TriggeringPolicy getTriggeringPolicy() {
+  public TriggeringPolicy<E> getTriggeringPolicy() {
     return triggeringPolicy;
   }
 

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java	Fri Jul 31 21:11:53 2009
@@ -31,9 +31,7 @@
   }
 
   public void start() {
-
     DateTokenConverter dtc = tbrp.fileNamePattern.getDateTokenConverter();
-
     if (dtc == null) {
       throw new IllegalStateException("FileNamePattern ["
           + tbrp.fileNamePattern.getPattern()

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java	Fri Jul 31 21:11:53 2009
@@ -84,9 +84,14 @@
     }
   }
 
-  public void setTimeBasedTriggering(TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering) {
+  public void setTimeBasedFileNamingAndTriggeringPolicy(TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering) {
     this.timeBasedTriggering = timeBasedTriggering;
   }
+
+  public TimeBasedFileNamingAndTriggeringPolicy<E> getTimeBasedFileNamingAndTriggeringPolicy() {
+    return timeBasedTriggering;
+  }
+
   
   static String computeFileNameStr_WCS(String fileNamePatternStr,
       CompressionMode compressionMode) {

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java	Fri Jul 31 21:11:53 2009
@@ -29,17 +29,17 @@
  */
 public class ScaffoldingForRollingTests {
 
-  static final String DATE_PATTERN_WITH_SECONDS = "yyyy-MM-dd_HH_mm_ss";
-  SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN_WITH_SECONDS);
+  static public final String DATE_PATTERN_WITH_SECONDS = "yyyy-MM-dd_HH_mm_ss";
+  static public final SimpleDateFormat SDF = new SimpleDateFormat(DATE_PATTERN_WITH_SECONDS);
 
   int diff = RandomUtil.getPositiveInt();
-  String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/";
+  protected String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "/";
   EchoLayout<Object> layout = new EchoLayout<Object>();
   Context context = new ContextBase();
-  List<String> expectedFilenameList = new ArrayList<String>();
+  protected List<String> expectedFilenameList = new ArrayList<String>();
 
-  long nextRolloverThreshold; // initialized in setUp()
-  long currentTime; // initialized in setUp()
+  protected long nextRolloverThreshold; // initialized in setUp()
+  protected long currentTime; // initialized in setUp()
   Calendar cal = Calendar.getInstance();
 
   public void setUp() {
@@ -117,16 +117,16 @@
   }
 
   // assuming rollover every second
-  void recomputeRolloverThreshold(long ct) {
+  protected void recomputeRolloverThreshold(long ct) {
     long delta = ct % 1000;
     nextRolloverThreshold = (ct - delta) + 1000;
   }
 
-  boolean passThresholdTime(long nextRolloverThreshold) {
+  protected boolean passThresholdTime(long nextRolloverThreshold) {
     return currentTime >= nextRolloverThreshold;
   }
 
-  void incCurrentTime(long increment) {
+  protected void incCurrentTime(long increment) {
     currentTime += increment;
   }
 
@@ -135,6 +135,30 @@
     return new Date(currentTime - delta);
   }
 
+  protected Date getDateOfPreviousPeriodsStart() {
+    long delta = currentTime % 1000;
+    return new Date(currentTime - delta - 1000);
+  }
+  
+  protected void addExpectedFileName_ByDate(String testId, Date date, boolean gzExtension) {
+   
+    String fn = randomOutputDir + testId + "-"
+        + SDF.format(date);
+    System.out.println("adding "+fn);
+    if (gzExtension) {
+      fn += ".gz";
+    } 
+    expectedFilenameList.add(fn);
+  }
+  
+  protected void addExpectedFileNamedIfItsTime_ByDate(String testId, boolean gzExtension) {
+    if (passThresholdTime(nextRolloverThreshold)) {
+      addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(),
+          gzExtension);
+      recomputeRolloverThreshold(currentTime);
+    }
+  }
+  
   String addGZIfNotLast(int i) {
     int lastIndex = expectedFilenameList.size() - 1;
     if (i != lastIndex) {

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java	Fri Jul 31 21:11:53 2009
@@ -47,7 +47,7 @@
 
     tbrp.setContext(context);
     satbfnatPolicy.setMaxFileSize("" + sizeThreshold);
-    tbrp.setTimeBasedTriggering(satbfnatPolicy);
+    tbrp.setTimeBasedFileNamingAndTriggeringPolicy(satbfnatPolicy);
     tbrp.setFileNamePattern(filenamePattern);
     tbrp.setParent(rfa);
     tbrp.timeBasedTriggering.setCurrentTime(givenTime);
@@ -60,7 +60,7 @@
   }
 
   @Test
-  public void noCompression_FileBSet_NoRestart_1() throws Exception {
+  public void noCompression_FileSet_NoRestart_1() throws Exception {
     String testId = "test1";
     String file = randomOutputDir + "toto.log";
     initRFA(rfa1, file);
@@ -152,7 +152,7 @@
   void addExpectedFileName(String testId, Date date, int fileIndexCounter,
       boolean gzExtension) {
 
-    String fn = randomOutputDir + testId + "-" + sdf.format(date) + "-"
+    String fn = randomOutputDir + testId + "-" + SDF.format(date) + "-"
         + fileIndexCounter + ".txt";
     if (gzExtension) {
       fn += ".gz";

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java	Fri Jul 31 21:11:53 2009
@@ -363,23 +363,6 @@
     addExpectedFileName_ByFile(file);
   }
 
-  void addExpectedFileName_ByDate(String testId, Date date, boolean gzExtension) {
-    String fn = randomOutputDir + testId + "-"
-        + sdf.format(date);
-    if (gzExtension) {
-      fn += ".gz";
-    } 
-    expectedFilenameList.add(fn);
-  }
- 
-  void addExpectedFileNamedIfItsTime_ByDate(String testId, boolean gzExtension) {
-    if (passThresholdTime(nextRolloverThreshold)) {
-      addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(),
-          gzExtension);
-      recomputeRolloverThreshold(currentTime);
-    }
-  }
-
   void addExpectedFileName_ByFile(String filenameSuffix) {
     String fn = randomOutputDir + filenameSuffix;
     expectedFilenameList.add(fn);


More information about the logback-dev mailing list