| 1 13 package com.tonbeller.wcf.log; 14 15 import java.io.File ; 16 import java.io.IOException ; 17 import java.util.Locale ; 18 19 import org.w3c.dom.Document ; 20 21 import com.tonbeller.wcf.component.Component; 22 import com.tonbeller.wcf.controller.RequestContext; 23 import com.tonbeller.wcf.form.FormComponent; 24 import com.tonbeller.wcf.format.FormatException; 25 import com.tonbeller.wcf.utils.SoftException; 26 27 30 public class LogForm extends FormComponent { 31 32 LogHandler logHandler; 33 String logDir; 34 35 String logConf = LogHandler.getDefault(); 37 String logVersion; 38 39 46 public LogForm(String id, Component parent, Document doc, String logDir) throws Exception { 47 super(id, parent, doc); 48 49 this.logDir = logDir; 50 } 51 52 55 public void initialize(RequestContext context) throws Exception { 56 try { 57 String ctxname = context.getRequest().getContextPath(); 58 if(ctxname.startsWith("/")) 59 ctxname = ctxname.substring(1); 60 61 this.logHandler = createLogHandler(logDir, context.getLocale(), ctxname); 62 this.logVersion = logHandler.version(); 63 } catch(IOException e) { 64 throw new SoftException(e); 65 } 66 67 super.initialize(context); 69 } 70 71 76 protected LogHandler createLogHandler(String logDir, Locale locale, String ctxname) throws IOException { 77 return new LogHandler(logDir, locale, ctxname); 78 } 79 80 84 public LogHandler getLogHandler() { 85 return logHandler; 86 } 87 88 92 public String getLogConf() { 93 return logConf; 94 } 95 96 100 public void setLogConf(String logConf) { 101 this.logConf = logConf; 102 try { 103 logHandler.applyConfig(logConf); 104 } catch(Exception e) { 105 String msg = e.getMessage(); 106 if(msg == null) 107 msg = e.toString(); 108 throw new FormatException(msg); 109 } 110 } 111 112 116 public String getLogVersion() { 117 return logVersion; 118 } 119 120 124 public String getLogFile() { 125 return logHandler.getLogFile().getAbsolutePath(); 126 } 127 128 132 public void setLogFile(String logFile) { 133 logHandler.setLogFile(new File (logFile)); 134 } 135 136 140 public String getLogLevel() { 141 return logHandler.getRootLoggerLevel(); 142 } 143 144 } 145 | Popular Tags |