You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2003/05/22 18:22:43 UTC

cvs commit: jakarta-log4j/tests/src/java/org/apache/log4j/rolling SizeBasedRollingTestCase.java TimeBasedRollingTestCase.java

ceki        2003/05/22 09:22:41

  Modified:    src/java/org/apache/log4j/rolling/helpers Compress.java
                        FileNamePattern.java RollingCalendar.java
               src/java/org/apache/log4j/rolling RollingFileAppender.java
                        SlidingWindowRollingPolicy.java
                        TimeBasedRollingPolicy.java
               tests/src/java/org/apache/log4j/rolling
                        SizeBasedRollingTestCase.java
                        TimeBasedRollingTestCase.java
  Log:
  
  Compression mode is now deduced automatically from the file name pattern.
  
  TestCases to follow.
  
  
  Revision  Changes    Path
  1.5       +39 -24    jakarta-log4j/src/java/org/apache/log4j/rolling/helpers/Compress.java
  
  Index: Compress.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/rolling/helpers/Compress.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Compress.java	21 May 2003 20:30:17 -0000	1.4
  +++ Compress.java	22 May 2003 16:22:33 -0000	1.5
  @@ -52,6 +52,7 @@
   import org.apache.log4j.Logger;
   
   import java.io.*;
  +
   import java.util.zip.GZIPOutputStream;
   import java.util.zip.ZipEntry;
   import java.util.zip.ZipOutputStream;
  @@ -69,8 +70,9 @@
     public static final String NONE_STR = "NONE";
     public static final String GZ_STR = "GZ";
     public static final String ZIP_STR = "ZIP";
  -   
  -  public static void ZIPCompress(String nameOfFile2zip, String nameOfZippedFile) {
  +
  +  public static void ZIPCompress(
  +    String nameOfFile2zip, String nameOfZippedFile) {
       File file2zip = new File(nameOfFile2zip);
   
       if (!file2zip.exists()) {
  @@ -83,8 +85,9 @@
       if (!nameOfZippedFile.endsWith(".zip")) {
         nameOfZippedFile = nameOfZippedFile + ".zip";
       }
  -    
  +
       File zippedFile = new File(nameOfZippedFile);
  +
       if (zippedFile.exists()) {
         logger.warn(
           "The target compressed file named [" + nameOfZippedFile
  @@ -92,27 +95,33 @@
   
         return;
       }
  -    
  +
       try {
  -         FileOutputStream fos = new FileOutputStream(nameOfZippedFile);
  -         ZipOutputStream zos = new ZipOutputStream(fos);
  -         FileInputStream fis = new FileInputStream(nameOfFile2zip);
  -      
  -         ZipEntry zipEntry = new ZipEntry(file2zip.getName());
  -         zos.putNextEntry(zipEntry);  
  -         byte[] inbuf = new byte[8102];
  -         int n;
  -         while ((n = fis.read(inbuf)) != -1) {
  -           zos.write(inbuf, 0, n);
  -         }
  -
  -         fis.close();
  -         zos.close();
  -       } catch (Exception e) {
  -         logger.error(
  -           "Error occured while compressing [" + nameOfFile2zip + "] into ["
  -           + nameOfZippedFile + "].", e);
  -       }
  +      FileOutputStream fos = new FileOutputStream(nameOfZippedFile);
  +      ZipOutputStream zos = new ZipOutputStream(fos);
  +      FileInputStream fis = new FileInputStream(nameOfFile2zip);
  +
  +      ZipEntry zipEntry = new ZipEntry(file2zip.getName());
  +      zos.putNextEntry(zipEntry);
  +
  +      byte[] inbuf = new byte[8102];
  +      int n;
  +
  +      while ((n = fis.read(inbuf)) != -1) {
  +        zos.write(inbuf, 0, n);
  +      }
  +
  +      fis.close();
  +      zos.close();
  +
  +      if (!file2zip.delete()) {
  +        logger.warn("Could not delete [" + nameOfFile2zip + "].");
  +      }
  +    } catch (Exception e) {
  +      logger.error(
  +        "Error occured while compressing [" + nameOfFile2zip + "] into ["
  +        + nameOfZippedFile + "].", e);
  +    }
     }
   
     public static void GZCompress(String nameOfFile2gz) {
  @@ -120,9 +129,10 @@
       // add te .gz exention to the second argument 
       GZCompress(nameOfFile2gz, nameOfFile2gz);
     }
  +
     public static void GZCompress(String nameOfFile2gz, String nameOfgzedFile) {
       File file2gz = new File(nameOfFile2gz);
  -    
  +
       if (!file2gz.exists()) {
         logger.warn(
           "The file to compress named [" + nameOfFile2gz + "] does not exist.");
  @@ -135,6 +145,7 @@
       }
   
       File gzedFile = new File(nameOfgzedFile);
  +
       if (gzedFile.exists()) {
         logger.warn(
           "The target compressed file named [" + nameOfgzedFile
  @@ -156,6 +167,10 @@
   
         fis.close();
         gzos.close();
  +
  +      if (!file2gz.delete()) {
  +        logger.warn("Could not delete [" + nameOfFile2gz + "].");
  +      }
       } catch (Exception e) {
         logger.error(
           "Error occured while compressing [" + nameOfFile2gz + "] into ["
  
  
  
  1.4       +2 -0      jakarta-log4j/src/java/org/apache/log4j/rolling/helpers/FileNamePattern.java
  
  Index: FileNamePattern.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/rolling/helpers/FileNamePattern.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileNamePattern.java	21 May 2003 18:59:59 -0000	1.3
  +++ FileNamePattern.java	22 May 2003 16:22:33 -0000	1.4
  @@ -78,6 +78,8 @@
   
       if (pattern != null) {
         patternLength = pattern.length();
  +      // We do not want to deal with trailing spaces in the pattern.
  +      this.pattern = this.pattern.trim();
       }
   
       parse();
  
  
  
  1.2       +70 -62    jakarta-log4j/src/java/org/apache/log4j/rolling/helpers/RollingCalendar.java
  
  Index: RollingCalendar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/rolling/helpers/RollingCalendar.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RollingCalendar.java	21 May 2003 18:59:59 -0000	1.1
  +++ RollingCalendar.java	22 May 2003 16:22:33 -0000	1.2
  @@ -46,45 +46,46 @@
    * Apache Software Foundation, please see <http://www.apache.org/>.
    *
    */
  +
   package org.apache.log4j.rolling.helpers;
   
  +import org.apache.log4j.Logger;
  +
   import java.text.SimpleDateFormat;
  +
   import java.util.Calendar;
   import java.util.Date;
   import java.util.GregorianCalendar;
   import java.util.Locale;
   import java.util.TimeZone;
   
  -import org.apache.log4j.Logger;
  -
   
   /**
  - 
  +
   /**
  - * RollingCalendar is a helper class to DailyRollingFileAppender or similar 
  - * timed-based rolling policies. Given a periodicity type and the current 
  + * RollingCalendar is a helper class to DailyRollingFileAppender or similar
  + * timed-based rolling policies. Given a periodicity type and the current
    * time, it computes the start of the next interval.
  - * 
  + *
    * @author Ceki G&uuml;lc&uuml;
  - * 
  + *
    * */
   public class RollingCalendar extends GregorianCalendar {
  -  
     static final Logger logger = Logger.getLogger(RollingCalendar.class);
  -  
  +
     // The gmtTimeZone is used only in computeCheckPeriod() method.
     static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
  -  
  +
     // The code assumes that the following constants are in a increasing
     // sequence.
  -  static final public int TOP_OF_TROUBLE = -1;
  -  static final public int TOP_OF_MINUTE = 0;
  -  static final public int TOP_OF_HOUR = 1;
  -  static final public int HALF_DAY = 2;
  -  static final public int TOP_OF_DAY = 3;
  -  static final public int TOP_OF_WEEK = 4;
  -  static final public int TOP_OF_MONTH = 5;
  -  
  +  public static final int TOP_OF_TROUBLE = -1;
  +  public static final int TOP_OF_SECOND = 0;
  +  public static final int TOP_OF_MINUTE = 1;
  +  public static final int TOP_OF_HOUR = 2;
  +  public static final int HALF_DAY = 3;
  +  public static final int TOP_OF_DAY = 4;
  +  public static final int TOP_OF_WEEK = 5;
  +  public static final int TOP_OF_MONTH = 6;
     int type = TOP_OF_TROUBLE;
   
     public RollingCalendar() {
  @@ -98,7 +99,7 @@
     public void init(String datePattern) {
       type = computeTriggeringPeriod(datePattern);
     }
  -  
  +
     public void setType(int type) {
       this.type = type;
     }
  @@ -107,59 +108,61 @@
       return getNextCheckDate(now).getTime();
     }
   
  -
     // This method computes the roll over period by looping over the
  -   // periods, starting with the shortest, and stopping when the r0 is
  -   // different from from r1, where r0 is the epoch formatted according
  -   // the datePattern (supplied by the user) and r1 is the
  -   // epoch+nextMillis(i) formatted according to datePattern. All date
  -   // formatting is done in GMT and not local format because the test
  -   // logic is based on comparisons relative to 1970-01-01 00:00:00
  -   // GMT (the epoch).
  -   public int computeTriggeringPeriod(String datePattern) {
  -     RollingCalendar rollingCalendar =
  -       new RollingCalendar(GMT_TIMEZONE, Locale.ENGLISH);
  -
  -     // set sate to 1970-01-01 00:00:00 GMT
  -     Date epoch = new Date(0);
  -
  -     if (datePattern != null) {
  -       for (int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) {
  -         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
  -         simpleDateFormat.setTimeZone(GMT_TIMEZONE); // do all date formatting in GMT
  -
  -         String r0 = simpleDateFormat.format(epoch);
  -         rollingCalendar.setType(i);
  -
  -         Date next = new Date(rollingCalendar.getNextCheckMillis(epoch));
  -         String r1 = simpleDateFormat.format(next);
  -
  -         //System.out.println("Type = "+i+", r0 = "+r0+", r1 = "+r1);
  -         if ((r0 != null) && (r1 != null) && !r0.equals(r1)) {
  -           return i;
  -         }
  -       }
  -     }
  -     return TOP_OF_TROUBLE; // Deliberately head for trouble...
  -   }
  -   
  -   
  +  // periods, starting with the shortest, and stopping when the r0 is
  +  // different from from r1, where r0 is the epoch formatted according
  +  // the datePattern (supplied by the user) and r1 is the
  +  // epoch+nextMillis(i) formatted according to datePattern. All date
  +  // formatting is done in GMT and not local format because the test
  +  // logic is based on comparisons relative to 1970-01-01 00:00:00
  +  // GMT (the epoch).
  +  public int computeTriggeringPeriod(String datePattern) {
  +    RollingCalendar rollingCalendar =
  +      new RollingCalendar(GMT_TIMEZONE, Locale.ENGLISH);
  +
  +    // set sate to 1970-01-01 00:00:00 GMT
  +    Date epoch = new Date(0);
  +
  +    if (datePattern != null) {
  +      for (int i = TOP_OF_SECOND; i <= TOP_OF_MONTH; i++) {
  +        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
  +        simpleDateFormat.setTimeZone(GMT_TIMEZONE); // do all date formatting in GMT
  +
  +        String r0 = simpleDateFormat.format(epoch);
  +        rollingCalendar.setType(i);
  +
  +        Date next = new Date(rollingCalendar.getNextCheckMillis(epoch));
  +        String r1 = simpleDateFormat.format(next);
  +
  +        //System.out.println("Type = "+i+", r0 = "+r0+", r1 = "+r1);
  +        if ((r0 != null) && (r1 != null) && !r0.equals(r1)) {
  +          return i;
  +        }
  +      }
  +    }
  +
  +    return TOP_OF_TROUBLE; // Deliberately head for trouble...
  +  }
  +
     public void printPeriodicity() {
       switch (type) {
  +    case TOP_OF_SECOND:
  +      logger.debug("Rollover every second.");
  +
  +      break;
  +
       case TOP_OF_MINUTE:
         logger.debug("Rollover every minute.");
   
         break;
   
       case TOP_OF_HOUR:
  -      logger.debug(
  -        "Rollover at the top of every hour.");
  +      logger.debug("Rollover at the top of every hour.");
   
         break;
   
       case HALF_DAY:
  -      logger.debug(
  -        "Rollover at midday and midnight.");
  +      logger.debug("Rollover at midday and midnight.");
   
         break;
   
  @@ -174,8 +177,7 @@
         break;
   
       case TOP_OF_MONTH:
  -      logger.debug(
  -        "Rollover at start of every month.");
  +      logger.debug("Rollover at start of every month.");
   
         break;
   
  @@ -183,11 +185,17 @@
         logger.warn("Unknown periodicity.");
       }
     }
  -  
  +
     public Date getNextCheckDate(Date now) {
       this.setTime(now);
   
       switch (type) {
  +    case TOP_OF_SECOND:
  +      this.set(Calendar.MILLISECOND, 0);
  +      this.add(Calendar.SECOND, 1);
  +
  +      break;
  +
       case TOP_OF_MINUTE:
         this.set(Calendar.SECOND, 0);
         this.set(Calendar.MILLISECOND, 0);
  
  
  
  1.12      +8 -1      jakarta-log4j/src/java/org/apache/log4j/rolling/RollingFileAppender.java
  
  Index: RollingFileAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/rolling/RollingFileAppender.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RollingFileAppender.java	21 May 2003 18:59:59 -0000	1.11
  +++ RollingFileAppender.java	22 May 2003 16:22:40 -0000	1.12
  @@ -91,6 +91,9 @@
         rollingPolicy.activateOptions();
         logger.debug("Active log file name: "+rollingPolicy.getActiveLogFileName());
         setFile(rollingPolicy.getActiveLogFileName());
  +      
  +      // the activeFile variable is used by the triggeringPolicy.isTriggeringEvent method
  +      activeFile = new File(rollingPolicy.getActiveLogFileName());
         super.activateOptions();
       } else {
         logger.warn("Please set a rolling policy");
  @@ -118,9 +121,13 @@
   
       rollingPolicy.rollover();
   
  -    // Altough not certain, the active file name may change after roll over.
  +    // Although not certain, the active file name may change after roll over.
       fileName = rollingPolicy.getActiveLogFileName();
       logger.debug("Active file name is now ["+fileName+"].");
  +
  +    // the activeFile variable is used by the triggeringPolicy.isTriggeringEvent method
  +    activeFile = new File(fileName);
  +
       try {
         // This will also close the file. This is OK since multiple
         // close operations are safe.
  
  
  
  1.9       +12 -2     jakarta-log4j/src/java/org/apache/log4j/rolling/SlidingWindowRollingPolicy.java
  
  Index: SlidingWindowRollingPolicy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/rolling/SlidingWindowRollingPolicy.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SlidingWindowRollingPolicy.java	21 May 2003 18:59:59 -0000	1.8
  +++ SlidingWindowRollingPolicy.java	22 May 2003 16:22:40 -0000	1.9
  @@ -70,6 +70,7 @@
     int maxIndex;
     int minIndex;
     FileNamePattern fileNamePattern;
  +  String  fileNamePatternStr;
     String activeFileName;
    
     public SlidingWindowRollingPolicy() {
  @@ -122,6 +123,15 @@
         logger.warn("Setting maxIndex to equal minIndex.");
         maxIndex = minIndex;
       }
  +    
  +    switch(compressionMode) {
  +      case Compress.GZ: 
  +      if(!fileNamePatternStr.endsWith(".gz")) {    
  +        fileNamePatternStr = fileNamePatternStr + ".gz";
  +      } 
  +      break;
  +    }      
  +    fileNamePattern = new FileNamePattern(fileNamePatternStr);
     }
   
     /**
  @@ -138,7 +148,7 @@
     }
   
     public String getFileNamePattern() {
  -    return fileNamePattern.toString();
  +    return fileNamePatternStr;
     }
   
     public int getMaxIndex() {
  @@ -150,7 +160,7 @@
     }
   
     public void setFileNamePattern(String fnp) {
  -    fileNamePattern = new FileNamePattern(fnp);
  +    fileNamePatternStr = fnp;
     }
   
     public void setMaxIndex(int maxIndex) {
  
  
  
  1.3       +84 -22    jakarta-log4j/src/java/org/apache/log4j/rolling/TimeBasedRollingPolicy.java
  
  Index: TimeBasedRollingPolicy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/rolling/TimeBasedRollingPolicy.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TimeBasedRollingPolicy.java	21 May 2003 20:30:17 -0000	1.2
  +++ TimeBasedRollingPolicy.java	22 May 2003 16:22:40 -0000	1.3
  @@ -54,7 +54,7 @@
   import org.apache.log4j.rolling.helpers.DateTokenConverter;
   import org.apache.log4j.rolling.helpers.FileNamePattern;
   import org.apache.log4j.rolling.helpers.RollingCalendar;
  -import org.apache.log4j.spi.OptionHandler;
  +import org.apache.log4j.rolling.helpers.Util;
   
   import java.io.File;
   
  @@ -69,16 +69,36 @@
    */
   public class TimeBasedRollingPolicy extends RollingPolicySkeleton
     implements TriggeringPolicy {
  +    
     static final Logger logger = Logger.getLogger(TimeBasedRollingPolicy.class);
  +  
     FileNamePattern fileNamePattern;
  +  String fileNamePatternStr;
     RollingCalendar rc;
     long nextCheck;
     Date now = new Date();
  -  String oldFileName = null;
  +  String currentFileName = null;
  +  String activeFileName;
   
     public void activateOptions() {
       // find out period from the filename pattern
  -    if (fileNamePattern != null) {
  +    if (fileNamePatternStr != null) {
  +      int len = fileNamePatternStr.length();
  +      
  +      if (fileNamePatternStr.endsWith(".gz")) {
  +          logger.debug("Will use gz compression");
  +          fileNamePattern = new FileNamePattern(fileNamePatternStr.substring(0, len -3));
  +          compressionMode = Compress.GZ;
  +        } else if (fileNamePatternStr.endsWith(".zip")) {
  +          logger.debug("Will use zip compression");
  +          fileNamePattern = new FileNamePattern(fileNamePatternStr.substring(0, len -4));
  +          compressionMode = Compress.GZ;
  +        } else {
  +          fileNamePattern = new FileNamePattern(fileNamePatternStr);
  +          compressionMode = Compress.NONE;
  +        }
  +      }
  +      
         DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
   
         if (dtc == null) {
  @@ -98,31 +118,64 @@
         now.setTime(n);
         nextCheck = rc.getNextCheckMillis(now);
   
  -      Date x = new Date();
  -      x.setTime(nextCheck);
  -      logger.debug("Next check set to: " + x);
  -    }
  +      //Date nc = new Date();
  +      //nc.setTime(nextCheck);
  +      //logger.debug("Next check set to: " + nc);  
     }
   
  +
  +  /**
  +   * 
  +   * The active log file is determined by the value of the activeFileName 
  +   * option if it is set. However, in case the activeFileName is left blank, 
  +   * then, the active log file equals the file name for the current period
  +   * as computed by the fileNamePattern.
  +   *  
  +   */
     public String getActiveLogFileName() {
  -    return fileNamePattern.convert(now);
  +    if (activeFileName == null) {
  +      return fileNamePattern.convert(now);
  +    } else {
  +      return activeFileName;
  +    }
     }
   
     public void rollover() {
  -    
       logger.debug("rollover called");
  -    logger.debug("compressionMode: "+compressionMode);
  -    if (oldFileName != null) {
  -      logger.debug("oldFileName != null");
  +    logger.debug("compressionMode: " + compressionMode);
  +
  +
  +    // if active file name is not set, then the active logging 
  +    // file is given by the value of currentFileName variable.
  +    if (activeFileName == null) {
  +      if (currentFileName != null) {
  +        //logger.debug("currentFileName != null");
  +
  +        switch (compressionMode) {
  +        case Compress.NONE:
  +
  +          // nothing to do;
  +          break;
  +
  +        case Compress.GZ:
  +          logger.debug("Compressing [" + currentFileName + "]");
  +          Compress.GZCompress(currentFileName);
  +
  +          break;
  +        }
  +      }
  +    } else { // if activeFileName != null, then the value of the
  +      // active logging is given by activeFileName
  +
         switch (compressionMode) {
         case Compress.NONE:
  +        Util.rename(activeFileName, currentFileName);
   
  -        // nothing to do;
           break;
   
         case Compress.GZ:
  -        logger.debug("Compressing ["+oldFileName+"]");
  -        Compress.GZCompress(oldFileName);
  +        logger.debug("Compressing [" + currentFileName + "]");
  +        Compress.GZCompress(activeFileName, currentFileName);
   
           break;
         }
  @@ -130,22 +183,23 @@
     }
   
     public void setFileNamePattern(String fnp) {
  -    fileNamePattern = new FileNamePattern(fnp);
  +    fileNamePatternStr = fnp;
     }
   
     public boolean isTriggeringEvent(File file) {
       //logger.debug("Is triggering event called");
  -
       long n = System.currentTimeMillis();
   
       if (n >= nextCheck) {
         logger.debug("Time to trigger rollover");
  -      
  -      // we set the oldFileName before we set the 'now' variable
  -      oldFileName = fileNamePattern.convert(now);
  -      
  +
  +      // We set the oldFileName before we set the 'now' variable
  +      // The currentFileName is the currently active file name when
  +      // the activeFileName is not set specifically by the user.
  +      currentFileName = fileNamePattern.convert(now);
  +
         now.setTime(n);
  -      logger.debug("ActiveLogFileName will return " + getActiveLogFileName());
  +      //logger.debug("ActiveLogFileName will return " + getActiveLogFileName());
         nextCheck = rc.getNextCheckMillis(now);
   
         //logger.debug("nextCheck is :"+nextCheck);
  @@ -157,5 +211,13 @@
       } else {
         return false;
       }
  +  }
  +
  +  public String getActiveFileName() {
  +    return activeFileName;
  +  }
  +
  +  public void setActiveFileName(String string) {
  +    activeFileName = string;
     }
   }
  
  
  
  1.8       +36 -1     jakarta-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTestCase.java
  
  Index: SizeBasedRollingTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SizeBasedRollingTestCase.java	19 May 2003 13:50:10 -0000	1.7
  +++ SizeBasedRollingTestCase.java	22 May 2003 16:22:40 -0000	1.8
  @@ -80,6 +80,9 @@
     }
   
     public void test1() throws Exception {
  +    
  +    // this test is invalid because setting the activeFileName variable
  +    // is now mandatory.
       Logger root = Logger.getRootLogger();
       root.addAppender(new ConsoleAppender(new PatternLayout()));
   
  @@ -145,7 +148,7 @@
   
       // Write exactly 10 bytes with each log
       for (int i = 0; i < 25; i++) {
  -      //Thread.sleep(1000);
  +      Thread.sleep(1000);
         if (i < 10) {
           logger.debug("Hello   " + i);
         } else if (i < 100) {
  @@ -170,6 +173,37 @@
            */
     }
   
  +  public void test3() throws Exception {
  +     Logger root = Logger.getRootLogger();
  +     root.addAppender(new ConsoleAppender(new PatternLayout()));
  +
  +     PatternLayout layout = new PatternLayout("%m\n");
  +     RollingFileAppender rfa = new RollingFileAppender();
  +     rfa.setLayout(layout);
  +
  +     SlidingWindowRollingPolicy swrp = new SlidingWindowRollingPolicy();
  +     SizeBasedTriggeringPolicy sbtp = new SizeBasedTriggeringPolicy();
  +
  +     swrp.setCompressionMode("GZ");
  +     sbtp.setMaxFileSize(100);
  +     swrp.setActiveFileName("output/sizeBased-test3");
  +     swrp.setFileNamePattern("output/sizeBased-test3.%i");
  +     rfa.setRollingPolicy(swrp);
  +     rfa.setTriggeringPolicy(sbtp);
  +     rfa.activateOptions();
  +     root.addAppender(rfa);
  +
  +     // Write exactly 10 bytes with each log
  +     for (int i = 0; i < 25; i++) {
  +       Thread.sleep(1000);
  +       if (i < 10) {
  +         logger.debug("Hello   " + i);
  +       } else if (i < 100) {
  +         logger.debug("Hello  " + i);
  +       }
  +     }
  +  }
  +
     boolean isWindows() {
       return System.getProperty("os.name").indexOf("Windows") != -1;
     }
  @@ -179,6 +213,7 @@
   
       //suite.addTest(new SizeBasedRollingTestCase("test1"));
       suite.addTest(new SizeBasedRollingTestCase("test2"));
  +    //suite.addTest(new SizeBasedRollingTestCase("test3"));
   
       return suite;
     }
  
  
  
  1.3       +38 -13    jakarta-log4j/tests/src/java/org/apache/log4j/rolling/TimeBasedRollingTestCase.java
  
  Index: TimeBasedRollingTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/rolling/TimeBasedRollingTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TimeBasedRollingTestCase.java	21 May 2003 20:30:17 -0000	1.2
  +++ TimeBasedRollingTestCase.java	22 May 2003 16:22:40 -0000	1.3
  @@ -83,23 +83,21 @@
   
     public void test1() throws Exception {
       Logger root = Logger.getRootLogger();
  -    root.addAppender(new ConsoleAppender(new PatternLayout()));
  +    root.addAppender(new ConsoleAppender(new PatternLayout("%d %5p %c{1} %m%n")));
   
  -    // We purposefully use the \n as the line separator. 
  -    // This makes the regression test system indepent.
  -    PatternLayout layout = new PatternLayout("%d %m\n");
  +    PatternLayout layout = new PatternLayout("%d %5p %c{1} %m%n");
       RollingFileAppender rfa = new RollingFileAppender();
       rfa.setLayout(layout);
   
       TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
  -    tbrp.setFileNamePattern("output/tbt%d{yyyy-MM-dd_HH_mm}");
  +    tbrp.setFileNamePattern("output/test1%d{yyyy-MM-dd_HH_mm_ss}.gz");
       rfa.setRollingPolicy(tbrp);
       rfa.activateOptions();
       root.addAppender(rfa);
   
  -    // Write exactly 10 bytes with each log
  -    for (int i = 0; i < 30; i++) {
  -      Thread.sleep(1000);
  +
  +    for (int i = 0; i < 5; i++) {
  +      Thread.sleep(500);
         if (i < 10) {
           logger.debug("Hello---" + i);
         } else if (i < 100) {
  @@ -123,15 +121,14 @@
         rfa.setLayout(layout);
   
         TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
  -      tbrp.setFileNamePattern("output/tbt%d{yyyy-MM-dd_HH_mm}");
  -      tbrp.setCompressionMode(Compress.GZ_STR);
  +      tbrp.setFileNamePattern("output/test2%d{yyyy-MM-dd_HH_mm_ss}");
         rfa.setRollingPolicy(tbrp);
         rfa.activateOptions();
         root.addAppender(rfa);
   
         // Write exactly 10 bytes with each log
         for (int i = 0; i < 30; i++) {
  -        Thread.sleep(1000);
  +        Thread.sleep(100);
           if (i < 10) {
             logger.debug("Hello---" + i);
           } else if (i < 100) {
  @@ -145,12 +142,40 @@
       }
   
   
  +  public void test3() throws Exception {
  +      Logger root = Logger.getRootLogger();
  +      root.addAppender(new ConsoleAppender(new PatternLayout()));
  +
  +      // We purposefully use the \n as the line separator. 
  +      // This makes the regression test system indepent.
  +      PatternLayout layout = new PatternLayout("%d %c %m\n");
  +      RollingFileAppender rfa = new RollingFileAppender();
  +      rfa.setLayout(layout);
  +
  +      TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
  +      tbrp.setFileNamePattern("output/test2%d{yyyy-MM-dd_HH_mm}.gz");
  +      rfa.setRollingPolicy(tbrp);
  +      rfa.activateOptions();
  +      root.addAppender(rfa);
  +
  +      // Write exactly 10 bytes with each log
  +      for (int i = 0; i < 20; i++) {
  +        Thread.sleep(1000);
  +        if (i < 10) {
  +          logger.debug("Hello---" + i);
  +        } else if (i < 100) {
  +          logger.debug("Hello--" + i);
  +        }
  +      }
  +    }
  +
     public static Test suite() {
       TestSuite suite = new TestSuite();
   
       //suite.addTest(new TimeBasedRollingTestCase("test1"));
  -    suite.addTest(new TimeBasedRollingTestCase("test2"));
  -
  +    //suite.addTest(new TimeBasedRollingTestCase("test2"));
  +    suite.addTest(new TimeBasedRollingTestCase("test3"));
  +    
       return suite;
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org