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 bu...@apache.org on 2012/07/11 13:48:09 UTC

[Bug 53536] New: RollingFileAppender with TimeBasedRolling policy doesn't create parent-path if FileNamePattern contains date pattern as directory

https://issues.apache.org/bugzilla/show_bug.cgi?id=53536

          Priority: P2
            Bug ID: 53536
                CC: log4j-dev@logging.apache.org
          Assignee: log4j-dev@logging.apache.org
           Summary: RollingFileAppender with TimeBasedRolling policy
                    doesn't create parent-path if FileNamePattern contains
                    date pattern as directory
          Severity: major
    Classification: Unclassified
          Reporter: daniel.stankiewicz@asseco.pl
          Hardware: PC
            Status: NEW
           Version: 1.2.17
         Component: Companions
           Product: Log4j

Created attachment 29048
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=29048&action=edit
Log4j XML configuration

I'm using org.apache.log4j.rolling.RollingFileAppender together with
org.apache.log4j.rolling.TimeBasedRollingPolicy to rotate log files
periodically. I need log files to be placed in directories based on date
pattern.

Unfortunately, the first log file is created properly, while after rollover
RollingFileAppender doesn't check if for newly calculated log file path the
whole directory path exists and tries to create FileOutputStream directly,
which causes FileNotFoundException:

log4j:WARN Exception during rollover, rollover deferred.
java.io.FileNotFoundException: c:\ssr\log\20120711_1336\ssr.log (The system
cannot find the path specified)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
    at
org.apache.log4j.rolling.RollingFileAppender.rollover(RollingFileAppender.java:286)
    at
org.apache.log4j.rolling.RollingFileAppender.subAppend(RollingFileAppender.java:353)
    at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at
org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.info(Category.java:666)
    at asseco.ssr.common.Log4jTests.main(Log4jTests.java:21)

The similar bug 9150 was filled for base Log4J FileAppender class and it is now
fixed. That's why first log file is created successfully. But during rollover()
in RollingFileAppender new FileOutputStream is created without creating a new
parent directory, which results in the above exception and the file is not
rolled.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.

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


[Bug 53536] RollingFileAppender with TimeBasedRolling policy doesn't create parent-path if FileNamePattern contains date pattern as directory

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53536

grobmeier <gr...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from grobmeier <gr...@gmail.com> ---
Thanks for the patch! 

I used the duplicated method. You are right, it should be refactored. But with
log4j 2 arriving to stable soon, we are minimizing our efforts to log4j 1

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.

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


[Bug 53536] RollingFileAppender with TimeBasedRolling policy doesn't create parent-path if FileNamePattern contains date pattern as directory

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53536

Daniel Stankiewicz <da...@asseco.pl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Daniel Stankiewicz <da...@asseco.pl> ---
org.apache.log4j.FileAppender contains the following code for creating
FileOutputStream, which should be incorporated also to
org.apache.log4j.rolling.RollingFileAppender:

    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
          //
          String parentName = new File(fileName).getParent();
          if (parentName != null) {
             File parentDir = new File(parentName);
             if(!parentDir.exists() && parentDir.mkdirs()) {
                ostream = new FileOutputStream(fileName, append);
             } else {
                throw ex;
             }
          } else {
             throw ex;
          }
    }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.

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


[Bug 53536] RollingFileAppender with TimeBasedRolling policy doesn't create parent-path if FileNamePattern contains date pattern as directory

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=53536

--- Comment #2 from Daniel Stankiewicz <da...@asseco.pl> ---
Created attachment 29049
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=29049&action=edit
Proposed patch

The code of proposed patch is copied from
org.apache.log4j.FileAppender.setFile(String, boolean, boolean, int) method.

It would be best to extract this functionality in FileAppender to another
protected method so that derived classes (like
org.apache.log4j.rolling.RollingFileAppender) could use the method and the code
wouldn't be duplicated.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.

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