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; } } ...
Created attachment 6619 [details] Consolidate checks for filename in FileAppender
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.
*** Bug 34216 has been marked as a duplicate of this bug. ***
Reopening per http://marc.theaimsgroup.com/?t=111901682200002&r=1&w=2
1.2.12 candidate
*** Bug 35794 has been marked as a duplicate of this bug. ***
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.
*** Bug 28836 has been marked as a duplicate of this bug. ***