Bug 9150 - No check in FileAppender if parent-path exists
Summary: No check in FileAppender if parent-path exists
Status: RESOLVED FIXED
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: PC All
: P3 major
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
: 28836 34216 35794 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-05-16 07:57 UTC by T.Nenninger
Modified: 2006-04-20 14:11 UTC (History)
3 users (show)



Attachments
Consolidate checks for filename in FileAppender (494 bytes, text/plain)
2003-06-04 07:52 UTC, Ulrich Bode
Details

Note You need to log in before you can comment on or make changes to this bug.
Description T.Nenninger 2002-05-16 07:57:34 UTC
When using the PropertyConfigurator containing a link to a FileAppender and the 
path to the requested log-file does not exist you get internal LOG4J-errors but 
no log-file.
From my point of view there's a bug in the method 'setFile(String file)' in the 
class 'FileAppender.java'.

I tried to solve the problem and find following solution (only with a few 
tests):


...
  public void setFile(String file)
  {
    // Trim spaces from both ends. The users probably does not want
    // trailing spaces in file names.
    String val = file.trim();
    fileName = val;

    File tempFile = new File(fileName);
    if (!(fileName.equals("")) && (tempFile.getParentFile() != null) && 
(tempFile.getParentFile().mkdirs()))
    {
      LogLog.debug("Create necessary directories '"+tempFile.getParentFile()+"' 
for log-file '"+tempFile.getName()+"'");
    }

    if ((!(fileName.equals(""))) && ((tempFile.canWrite() || !(tempFile.exists
()))))
    {
      LogLog.debug("Set filename for FileAppender '"+fileName+"'");
    }
    else
    {
      LogLog.debug("Can't set filename for FileAppender to '"+fileName+"'; 
possible no write-access or undefined path");
      fileName = null;
    }
  }
...
Comment 1 Ulrich Bode 2003-06-04 07:52:15 UTC
Created attachment 6619 [details]
Consolidate checks for filename in FileAppender
Comment 2 Yoav Shapira 2004-12-10 19:10:46 UTC
We can't assume log4j will have directory creation permissions, only write 
permissions to the file specified in the configuration.  It's up to the server 
administrator to control the directory tree.  Hence, RESOLVE/WONTFIX on this 
patch.
Comment 3 Curt Arnold 2005-03-29 03:16:56 UTC
*** Bug 34216 has been marked as a duplicate of this bug. ***
Comment 4 Curt Arnold 2005-06-17 23:53:02 UTC
Reopening per http://marc.theaimsgroup.com/?t=111901682200002&r=1&w=2
Comment 5 Mark Womack 2005-06-18 00:16:25 UTC
1.2.12 candidate
Comment 6 Curt Arnold 2005-07-19 22:41:45 UTC
*** Bug 35794 has been marked as a duplicate of this bug. ***
Comment 7 Curt Arnold 2005-07-22 21:55:30 UTC
Implemented in both 1.2 branch and CVS HEAD.

Not sure what was intended by the "Consolidate checks for filename" attachment.  Please refile as different 
bug if a problem persists.
Comment 8 Curt Arnold 2006-04-20 21:11:26 UTC
*** Bug 28836 has been marked as a duplicate of this bug. ***