logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject cvs commit: logging-log4j/tests/src/java/org/apache/log4j/rolling ObsoleteDailyRollingFileAppenderTest.java ObsoleteRollingFileAppenderTest.java SizeBasedRollingTest.java TimeBasedRollingTest.java
Date Tue, 08 Mar 2005 20:21:19 GMT
carnold     2005/03/08 12:21:18

  Modified:    src/java/org/apache/log4j/rolling
                        SizeBasedTriggeringPolicy.java
               tests/src/java/org/apache/log4j/rolling
                        SizeBasedRollingTest.java TimeBasedRollingTest.java
  Added:       src/java/org/apache/log4j DailyRollingFileAppender.java
                        RollingFileAppender.java
               tests/input/rolling obsoleteDRFA1.properties
                        obsoleteRFA1.properties
               tests/src/java/org/apache/log4j/rolling
                        ObsoleteDailyRollingFileAppenderTest.java
                        ObsoleteRollingFileAppenderTest.java
  Log:
  Bug 33914: Emulation of o.a.l.RollingFileAppender and o.a.l.DRFA
  
  Revision  Changes    Path
  1.32      +246 -218  logging-log4j/src/java/org/apache/log4j/DailyRollingFileAppender.java
  
  
  
  
  1.24      +244 -107  logging-log4j/src/java/org/apache/log4j/RollingFileAppender.java
  
  
  
  
  1.9       +8 -0      logging-log4j/src/java/org/apache/log4j/rolling/SizeBasedTriggeringPolicy.java
  
  Index: SizeBasedTriggeringPolicy.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/SizeBasedTriggeringPolicy.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SizeBasedTriggeringPolicy.java	12 Feb 2005 03:10:27 -0000	1.8
  +++ SizeBasedTriggeringPolicy.java	8 Mar 2005 20:21:18 -0000	1.9
  @@ -30,6 +30,14 @@
   public class SizeBasedTriggeringPolicy implements TriggeringPolicy {
     long maxFileSize = 10 * 1024 * 1024; // let 10 MB the default max size
   
  +  public SizeBasedTriggeringPolicy() {
  +  }
  +
  +  public SizeBasedTriggeringPolicy(final long maxFileSize) {
  +      this.maxFileSize = maxFileSize;
  +  }
  +
  +
     public boolean isTriggeringEvent(final File file, final LoggingEvent event) {
       //System.out.println("Size"+file.length());
       return (file.length() >= maxFileSize);
  
  
  
  1.1                  logging-log4j/tests/input/rolling/obsoleteDRFA1.properties
  
  Index: obsoleteDRFA1.properties
  ===================================================================
  log4j.rootLogger=DEBUG, testAppender
  log4j.appender.testAppender=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.testAppender.file=output/obsoleteDRFA-test1.log
  log4j.appender.testAppender.datePattern='.'yyyy-MM-dd_HH_mm_ss
  log4j.appender.testAppender.Append=false
  log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
  log4j.appender.testAppender.layout.ConversionPattern=%m%n
  
  #  Prevent internal log4j DEBUG messages from polluting the output.
  log4j.logger.org.apache.log4j.PropertyConfigurator=INFO
  log4j.logger.org.apache.log4j.config.PropertySetter=INFO
  log4j.logger.org.apache.log4j.FileAppender=INFO
  
  
  
  1.1                  logging-log4j/tests/input/rolling/obsoleteRFA1.properties
  
  Index: obsoleteRFA1.properties
  ===================================================================
  log4j.rootLogger=DEBUG, testAppender
  log4j.appender.testAppender=org.apache.log4j.RollingFileAppender
  log4j.appender.testAppender.file=output/obsoleteRFA-test1.log
  log4j.appender.testAppender.Append=false
  log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
  log4j.appender.testAppender.layout.ConversionPattern=%m\n
  log4j.appender.testAppender.maxFileSize=100
  
  #  Prevent internal log4j DEBUG messages from polluting the output.
  log4j.logger.org.apache.log4j.PropertyConfigurator=INFO
  log4j.logger.org.apache.log4j.config.PropertySetter=INFO
  log4j.logger.org.apache.log4j.FileAppender=INFO
  
  
  
  1.10      +20 -7     logging-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTest.java
  
  Index: SizeBasedRollingTest.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SizeBasedRollingTest.java	18 Feb 2005 17:23:43 -0000	1.9
  +++ SizeBasedRollingTest.java	8 Mar 2005 20:21:18 -0000	1.10
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999,2004 The Apache Software Foundation.
  + * Copyright 1999,2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -27,6 +27,8 @@
   import org.apache.log4j.PatternLayout;
   import org.apache.log4j.util.Compare;
   
  +import java.io.File;
  +
   
   /**
    *
  @@ -111,7 +113,11 @@
         }
       }
   
  -    // The File.length() method is not accurate under Windows    
  +    assertTrue(new File("output/sizeBased-test2.log").exists());
  +    assertTrue(new File("output/sizeBased-test2.0").exists());
  +    assertTrue(new File("output/sizeBased-test2.1").exists());
  +
  +    // The File.length() method is not accurate under Windows
   
        if(!isWindows()) {
   
  @@ -155,6 +161,10 @@
          }
        }
   
  +    assertTrue(new File("output/sbr-test3.log").exists());
  +    assertTrue(new File("output/sbr-test3.0.gz").exists());
  +    assertTrue(new File("output/sbr-test3.1.gz").exists());
  +
        if(!isWindows()) {
   
         assertTrue(Compare.compare("output/sbr-test3.log",  "witness/rolling/sbr-test3.log"));
  @@ -169,13 +179,16 @@
       return System.getProperty("os.name").indexOf("Windows") != -1;
     }
   
  +    /**
  +     * Build test suite using this class and ObsoleteRollingFileAppenderTest.
  +     *
  +     * @deprecated Marked deprecated since suite contains tests of deprecated classes
  +     * @return test suite.
  +     */
     public static Test suite() {
       TestSuite suite = new TestSuite();
  -
  -    suite.addTest(new SizeBasedRollingTest("test1"));
  -    suite.addTest(new SizeBasedRollingTest("test2"));
  -    suite.addTest(new SizeBasedRollingTest("test3"));
  -
  +    suite.addTestSuite(SizeBasedRollingTest.class);
  +    suite.addTestSuite(ObsoleteRollingFileAppenderTest.class);
       return suite;
     }
   }
  
  
  
  1.17      +9 -11     logging-log4j/tests/src/java/org/apache/log4j/rolling/TimeBasedRollingTest.java
  
  Index: TimeBasedRollingTest.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/rolling/TimeBasedRollingTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TimeBasedRollingTest.java	18 Feb 2005 17:23:43 -0000	1.16
  +++ TimeBasedRollingTest.java	8 Mar 2005 20:21:18 -0000	1.17
  @@ -475,19 +475,17 @@
       }
     }
   
  -  public static Test DISABLEDsuite() {
  +  /**
  +   * Build test suite using this class and ObsoleteDailyRollingFileAppenderTest.
  +   *
  +   * @deprecated Marked deprecated since suite contains tests of deprecated classes
  +   * @return test suite.
  +   */
  +  public static Test suite() {
       TestSuite suite = new TestSuite();
  +    suite.addTestSuite(TimeBasedRollingTest.class);
  +    suite.addTestSuite(ObsoleteDailyRollingFileAppenderTest.class);
   
  -    suite.addTest(new TimeBasedRollingTest("test1"));
  -//    suite.addTest(new TimeBasedRollingTest("test2"));
  -//    suite.addTest(new TimeBasedRollingTest("test3"));
  -//    suite.addTest(new TimeBasedRollingTest("test4"));
  -//
  -//    suite.addTest(new TimeBasedRollingTest("test5"));
  -//    suite.addTest(new TimeBasedRollingTest("test6"));
  -//    suite.addTest(new TimeBasedRollingTest("testWithJoran1"));
  -//    suite.addTest(new TimeBasedRollingTest("testWithJoran10"));
  -    
       return suite;
     }
   }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/rolling/ObsoleteDailyRollingFileAppenderTest.java
  
  Index: ObsoleteDailyRollingFileAppenderTest.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.rolling;
  
  import junit.framework.TestCase;
  
  import org.apache.log4j.*;
  
  import java.io.File;
  
  
  /**
   * Tests the emulation of org.apache.log4j.DailyRollingFileAppender
   *
   * @author Curt Arnold
   * @deprecated Class under test is deprecated.
   *
   */
  public class ObsoleteDailyRollingFileAppenderTest extends TestCase {
    Logger logger = Logger.getLogger(ObsoleteDailyRollingFileAppenderTest.class);
    Logger root = Logger.getRootLogger();
  
    public ObsoleteDailyRollingFileAppenderTest(final String name) {
      super(name);
    }
  
    public void setUp() {
    }
  
    public void tearDown() {
      LogManager.shutdown();
    }
  
    /**
     * Test basic rolling functionality.
     */
    public void test1() throws Exception {
      PropertyConfigurator.configure("input/rolling/obsoleteDRFA1.properties");
  
      int preCount = getFileCount("output", "obsoleteDRFA-test1.log.");
  
      for (int i = 0; i < 25; i++) {
        Thread.sleep(100);
        logger.debug("Hello---" + i);
      }
  
      int postCount = getFileCount("output", "obsoleteDRFA-test1.log.");
      assertTrue(postCount > preCount);
    }
  
    /**
     * Test basic rolling functionality.
     */
    public void test2() throws Exception {
      PatternLayout layout = new PatternLayout("%m%n");
      org.apache.log4j.DailyRollingFileAppender rfa =
        new org.apache.log4j.DailyRollingFileAppender();
      rfa.setName("ROLLING");
      rfa.setLayout(layout);
      rfa.setAppend(false);
      rfa.setFile("output/obsoleteDRFA-test2.log");
      rfa.setDatePattern("'.'yyyy-MM-dd-HH_mm_ss");
      rfa.activateOptions();
      root.addAppender(rfa);
  
      int preCount = getFileCount("output", "obsoleteDRFA-test2.log.");
  
      for (int i = 0; i < 25; i++) {
        Thread.sleep(100);
        logger.debug("Hello---" + i);
      }
  
      int postCount = getFileCount("output", "obsoleteDRFA-test2.log.");
      assertTrue(postCount > preCount);
    }
  
    private static int getFileCount(String dir, String initial) {
      String[] files = new File(dir).list();
      int count = 0;
  
      for (int i = 0; i < files.length; i++) {
        if (files[i].startsWith(initial)) {
          count++;
        }
      }
  
      return count;
    }
  }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/rolling/ObsoleteRollingFileAppenderTest.java
  
  Index: ObsoleteRollingFileAppenderTest.java
  ===================================================================
  /*
   * Copyright 1999,2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.rolling;
  
  import junit.framework.TestCase;
  
  import org.apache.log4j.*;
  
  import java.io.File;
  
  
  /**
   * Tests the emulation of org.apache.log4j.RollingFileAppender
   *
   * @author Curt Arnold
   * @deprecated Class under test is deprecated.
   *
   */
  public class ObsoleteRollingFileAppenderTest extends TestCase {
    Logger logger = Logger.getLogger(ObsoleteRollingFileAppenderTest.class);
    Logger root = Logger.getRootLogger();
  
    public ObsoleteRollingFileAppenderTest(final String name) {
      super(name);
    }
  
    public void setUp() {
    }
  
    public void tearDown() {
      LogManager.shutdown();
    }
  
    /**
     * Test basic rolling functionality.
     */
    public void test1() throws Exception {
      PropertyConfigurator.configure("input/rolling/obsoleteRFA1.properties");
  
      // Write exactly 10 bytes with each log
      for (int i = 0; i < 25; i++) {
        Thread.sleep(100);
  
        if (i < 10) {
          logger.debug("Hello---" + i);
        } else if (i < 100) {
          logger.debug("Hello--" + i);
        }
      }
  
      assertTrue(new File("output/obsoleteRFA-test1.log").exists());
      assertTrue(new File("output/obsoleteRFA-test1.log.1").exists());
    }
  
    /**
     * Test basic rolling functionality.
     */
    public void test2() throws Exception {
      PatternLayout layout = new PatternLayout("%m\n");
      org.apache.log4j.RollingFileAppender rfa =
        new org.apache.log4j.RollingFileAppender();
      rfa.setName("ROLLING");
      rfa.setLayout(layout);
      rfa.setAppend(false);
      rfa.setMaximumFileSize(100);
      rfa.setFile("output/obsoleteRFA-test2.log");
      rfa.activateOptions();
      root.addAppender(rfa);
  
      // Write exactly 10 bytes with each log
      for (int i = 0; i < 25; i++) {
        Thread.sleep(100);
  
        if (i < 10) {
          logger.debug("Hello---" + i);
        } else if (i < 100) {
          logger.debug("Hello--" + i);
        }
      }
  
      assertTrue(new File("output/obsoleteRFA-test2.log").exists());
      assertTrue(new File("output/obsoleteRFA-test2.log.1").exists());
    }
  }
  
  
  

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


Mime
View raw message