1 package de.webman.util.log4j; 2 3 import org.apache.log4j.Layout; 4 import org.apache.log4j.RollingFileAppender; 5 import com.teamkonzept.web.TKEvent; 6 import com.teamkonzept.web.servlet.ServletInterface; 7 import java.io.File ; 8 import java.io.IOException ; 9 10 15 public class WebmanRollingFileAppender extends RollingFileAppender 16 { 17 private static String documentRoot; 18 private boolean appended = false; 19 20 23 public WebmanRollingFileAppender() 24 { 25 super(); 26 } 27 28 33 public WebmanRollingFileAppender (Layout layout, String filename) throws java.io.IOException 34 { 35 super(); 36 String root = getDocRoot(); 38 if (root != null) 39 setFile(root + File.pathSeparator + filename); 40 else 41 setFile(filename); 42 43 setLayout(layout); 44 } 45 46 49 public void setFile(String name) 50 { 51 String root = getDocRoot(); 52 if (root != null) 54 super.setFile(root + File.separator+ name); 55 else 56 super.setFile(name); 57 58 } 59 60 63 public void setFile(String name, boolean append) throws java.io.IOException  64 { 65 String root = getDocRoot(); 66 if (root != null) 68 super.setFile(root + File.separator + name, append); 69 else 70 super.setFile(name, append); 71 72 } 73 74 public static void setDocRoot(String root) 75 { 76 documentRoot = root; 77 } 79 80 84 private String getDocRoot() 85 { 86 if (appended) return null; 88 String contextPath = null; 89 TKEvent event = TKEvent.getEventForThread(); 90 if(event != null){ 91 contextPath = ((ServletInterface)event.getHttpInterface()).getContextPath(); 92 } 93 else if(documentRoot != null){ 94 contextPath = documentRoot; 95 } 96 contextPath += "log" + File.separator; 97 appended = true; 98 File f = new File (contextPath); 100 if (!f.exists()) 101 f.mkdir(); 102 return contextPath; 103 } 104 105 } 106
| Popular Tags
|