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 FileAppenderTest.java
Date Fri, 22 Jul 2005 18:58:44 GMT
carnold     2005/07/22 11:58:44

  Modified:    src/java/org/apache/log4j Tag: v1_2-branch FileAppender.java
  Added:       tests/src/java/org/apache/log4j Tag: v1_2-branch
                        FileAppenderTest.java
  Log:
  Bug 9150: No check in FileAppender if parent-path exists
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.34.2.4  +22 -1     logging-log4j/src/java/org/apache/log4j/FileAppender.java
  
  Index: FileAppender.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/FileAppender.java,v
  retrieving revision 1.34.2.3
  retrieving revision 1.34.2.4
  diff -u -r1.34.2.3 -r1.34.2.4
  --- FileAppender.java	24 May 2005 05:06:17 -0000	1.34.2.3
  +++ FileAppender.java	22 Jul 2005 18:58:44 -0000	1.34.2.4
  @@ -20,6 +20,8 @@
   import java.io.Writer;
   import java.io.FileOutputStream;
   import java.io.BufferedWriter;
  +import java.io.FileNotFoundException;
  +import java.io.File;
   
   import org.apache.log4j.spi.ErrorCode;
   import org.apache.log4j.helpers.QuietWriter;
  @@ -279,7 +281,26 @@
       }
   
       reset();
  -    Writer fw = createWriter(new FileOutputStream(fileName, append));
  +    FileOutputStream ostream = null;
  +    try {
  +          //
  +          //   attempt to create file
  +          //
  +          ostream = new FileOutputStream(fileName, append);
  +    } catch(FileNotFoundException ex) {
  +          //
  +          //   if parent directory does not exist then
  +          //      attempt to create it and try to create file
  +          //      see bug 9150
  +          //
  +          File parentDir = new File(new File(fileName).getParent());
  +          if(!parentDir.exists() && parentDir.mkdirs()) {
  +              ostream = new FileOutputStream(fileName, append);
  +          } else {
  +              throw ex;
  +          }
  +    }
  +    Writer fw = createWriter(ostream);
       if(bufferedIO) {
         fw = new BufferedWriter(fw, bufferSize);
       }
  
  
  
  No                   revision
  No                   revision
  1.6.2.1   +5 -26     logging-log4j/tests/src/java/org/apache/log4j/FileAppenderTest.java
  
  Index: FileAppenderTest.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/FileAppenderTest.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- FileAppenderTest.java	22 Jul 2005 17:59:03 -0000	1.6
  +++ FileAppenderTest.java	22 Jul 2005 18:58:44 -0000	1.6.2.1
  @@ -16,37 +16,16 @@
   
   package org.apache.log4j;
   import java.io.File;
  +import junit.framework.TestCase;
   
   
   /**
    *
  - * Test if WriterAppender honors the Appender contract.
  + * FileAppender tests.
    *
  - * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
    * @author Curt Arnold
    */
  -public class FileAppenderTest extends AbstractAppenderTest {
  -  protected AppenderSkeleton getAppender() {
  -    return new FileAppender();
  -  }
  -
  -  protected AppenderSkeleton getConfiguredAppender() {
  -    FileAppender wa = new FileAppender();
  -    wa.setFile("output/temp");
  -    wa.setLayout(new DummyLayout());
  -    return wa;
  -  }
  -
  -  public void testPartiallyConfiguredAppender() {
  -    FileAppender wa1 = new FileAppender();
  -    wa1.setFile("output/temp");
  -    assertFalse(wa1.isActive());
  -
  -    FileAppender wa2 = new FileAppender();
  -    wa2.setLayout(new DummyLayout());
  -    assertFalse(wa2.isActive());
  -  }
  -
  +public class FileAppenderTest extends TestCase {
     /**
      * Tests that any necessary directories are attempted to
      * be created if they don't exist.  See bug 9150.
  @@ -58,9 +37,9 @@
         File newDir = new File("output/newdir");
         newDir.delete();
   
  -      FileAppender wa = new FileAppender();
  +      org.apache.log4j.FileAppender wa = new org.apache.log4j.FileAppender();
         wa.setFile("output/newdir/temp.log");
  -      wa.setLayout(new DummyLayout());
  +      wa.setLayout(new PatternLayout("%m%n"));
         wa.activateOptions();
   
         assertTrue(new File("output/newdir/temp.log").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