logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grobme...@apache.org
Subject svn commit: r1483280 - in /logging/log4j/companions/extras/trunk/src: changes/changes.xml main/java/org/apache/log4j/rolling/RollingFileAppender.java
Date Thu, 16 May 2013 09:41:02 GMT
Author: grobmeier
Date: Thu May 16 09:41:02 2013
New Revision: 1483280

URL: http://svn.apache.org/r1483280
Log:
53536: RollingFileAppender with TimeBasedRolling policy doesn't create parent-path if FileNamePattern
contains date pattern as directory (thanks to Daniel Stankiewicz)

Modified:
    logging/log4j/companions/extras/trunk/src/changes/changes.xml
    logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingFileAppender.java

Modified: logging/log4j/companions/extras/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/changes/changes.xml?rev=1483280&r1=1483279&r2=1483280&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/changes/changes.xml (original)
+++ logging/log4j/companions/extras/trunk/src/changes/changes.xml Thu May 16 09:41:02 2013
@@ -21,6 +21,7 @@
   </properties>
   <body>
     <release version="1.2" date="2013-05-04" description="Maintenance release">
+        <action action="fix" issue="53536">RollingFileAppender with TimeBasedRolling
policy doesn't create parent-path if FileNamePattern contains date pattern as directory (thanks
to Daniel Stankiewicz)</action>
         <action action="fix" issue="53645">DBAppender has a compile error (thanks to
Antonio Petrelli)</action>
         <action action="update">Prefixed FormattingInfo and PatternParser with Extras
to avoid classloading conflict</action>
         <action action="update">Fixed product naming</action>

Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingFileAppender.java?rev=1483280&r1=1483279&r2=1483280&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingFileAppender.java
(original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingFileAppender.java
Thu May 16 09:41:02 2013
@@ -30,6 +30,7 @@ import org.apache.log4j.xml.Unrecognized
 import org.w3c.dom.Element;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -285,8 +286,9 @@ public final class RollingFileAppender e
             } else {
               Writer newWriter =
                 createWriter(
-                  new FileOutputStream(
-                    rollover.getActiveFileName(), rollover.getAppend()));
+                    createFileOutputStream(
+                        rollover.getActiveFileName(), rollover.getAppend()));
+
               closeWriter();
               setFile(rollover.getActiveFileName());
               this.qw = createQuietWriter(newWriter);
@@ -335,6 +337,41 @@ public final class RollingFileAppender e
     return false;
   }
 
+ /**
+  * Creates a new FileOutputStream of a new log file, possibly creating first all the needed
parent directories
+  *
+  * @param newFileName Filename of new log file to be created
+  * @param append If file should be appended
+  * @return newly created FileOutputStream
+  * @throws FileNotFoundException if creating log file or parent directories was unsuccessful
+  */
+ private FileOutputStream createFileOutputStream(String newFileName, boolean append)
+         throws FileNotFoundException {
+    try {
+          //
+          //   attempt to create file
+          //
+          return new FileOutputStream(newFileName, append);
+    } catch(FileNotFoundException ex) {
+        //
+        //   if parent directory does not exist then
+        //      attempt to create it and try to create file
+        //      see bug 9150
+        //
+        String parentName = new File(newFileName).getParent();
+        if (parentName != null) {
+            File parentDir = new File(parentName);
+            if (!parentDir.exists() && parentDir.mkdirs()) {
+                return new FileOutputStream(newFileName, append);
+            } else {
+                throw ex;
+            }
+        } else {
+            throw ex;
+        }
+    }
+ }
+
   /**
    * {@inheritDoc}
   */



Mime
View raw message