1 22 package org.jboss.logging.appender; 23 24 import java.io.File ; 25 26 import java.net.URL ; 27 import java.net.MalformedURLException ; 28 29 import org.apache.log4j.helpers.LogLog; 30 31 38 public class FileAppender 39 extends org.apache.log4j.FileAppender 40 { 41 public void setFile(final String filename) 42 { 43 FileAppender.Helper.makePath(filename); 44 super.setFile(filename); 45 } 46 47 50 public static class Helper 51 { 52 public static void makePath(final String filename) 53 { 54 File dir; 55 56 try { 57 URL url = new URL (filename.trim()); 58 dir = new File (url.getFile()).getParentFile(); 59 } 60 catch (MalformedURLException e) { 61 dir = new File (filename.trim()).getParentFile(); 62 } 63 64 if (!dir.exists()) { 65 boolean success = dir.mkdirs(); 66 if (!success) { 67 LogLog.error("Failed to create directory structure: " + dir); 68 } 69 } 70 } 71 } 72 } 73 | Popular Tags |