Hello,

a few weeks ago I started to use the LOG4J (1.2beta?) ... it's great !!!
Now, I found a bug/missing feature in the FileAppender-class (I hope I use the LOG4J 
in the right way) :


Preconditions :
==========
When using the class 'PropertyConfigurator' for configuration the logging with a 
'FileAppender' configured inside, you can define
the full qualified output-file, e.g. :
...
log4j.appender.FILE_APPENDER=org.apache.log4j.FileAppender
log4j.appender.FILE_APPENDER.File=C:\TEMP\THIS_IS_A_TEST\TEST.LOG
...


Bug :
====
When the path ('C:\TEMP\THIS_IS_A_TEST\') exists this works fine, but when not the 
complete path exists (e.g. only 'C:\TEMP\') you
get following exception because the FileAppender-class can't access the file :
...
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: c:\temp\test\test.LOG (The system cannot find the path 
specified)
        at java.io.FileOutputStream.openAppend(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:100)
        at org.apache.log4j.FileAppender.setFile(FileAppender.java:276)
        at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:157)
        at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:249)
...


Solution :
=======
In the method 'setFile(...)' in the class 'FileAppender' (line 264) it should be 
possible (from my point of view) to create path(s)
if necessary using these few lines of code :
...
public synchronized void setFile(String fileName, boolean append, boolean bufferedIO, 
int bufferSize)   throws IOException
{
    File tempFile = new File(fileName);
    if (tempFile.getParentFile().mkdirs() == true)
    {
        LogLog.debug("Logfile-path '"+tempFile.getParentFile()+"' created; used for 
logfile '"+outputFile.getName()+"'");
    }

    ...


Kind regards
Thomas Nenninger



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to