[logback-dev] Mkdirs in FileAppender

Lilianne E. Blaze lilianne at lilianne-blaze.net
Wed Jul 23 01:03:18 CEST 2008

Could you please please consider adding the ability to create missing 
parent directories in FileAppender in Logback Core?

Suppose I have the following:

(tomcat home)/logs/

And I'd like for my webapp to automatically create a subdirectory, so 
after I run it I have:

(tomcat home)/logs/my-webapp/my-webapp.log

Right now if I just configure Logback to use the above path, it 
obviously fails, I have to create /my-webapp/ manually.

The code to do it (at least the most basic version is trivial, just 
modify   public synchronized void setFile() throws IOException {

so it contains:


     // modified code starts here
     if( mkdirs )
       File f = new File(fileName);
       File fParent = f.getParentFile();

       if( !fParent.exists() )
     // modified code ends here

     this.writer = createWriter(new FileOutputStream(fileName, append));

And obviously add mkdirs property and import java.io.File.

Greetings, Lilianne E. Blaze

More information about the logback-dev mailing list