1 22 package org.jboss.test.logging; 23 24 import java.net.URL ; 25 26 import org.apache.log4j.BasicConfigurator; 27 import org.apache.log4j.ConsoleAppender; 28 import org.apache.log4j.FileAppender; 29 import org.apache.log4j.Logger; 30 import org.apache.log4j.PatternLayout; 31 import org.jboss.logging.XLevel; 32 33 39 public class Log4jLoggingPlugin extends LoggingPlugin 40 { 41 public void enableTrace(String name) 42 { 43 Logger.getLogger(name).setLevel(XLevel.TRACE); 44 } 45 46 public void setUp() throws Exception 47 { 48 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 49 String file = System.getProperty("log4j.configuration"); 50 51 if (file == null) 53 { 54 URL url = cl.getResource("test-log4j.xml"); 55 if (url != null) 56 { 57 System.setProperty("log4j.configuration", "test-log4j.xml"); 58 BasicConfigurator.configure(); 59 return; 60 } 61 } 62 63 URL url = cl.getResource("log4j.xml"); 65 if (url != null) 66 { 67 System.err.println("Found log4j.xml: "+url); 68 System.err.flush(); 69 return; 70 } 71 url = cl.getResource("log4j.properties"); 72 if (url != null) 73 { 74 System.err.println("Found log4j.properties: "+url); 75 System.err.flush(); 76 return; 77 } 78 79 BasicConfigurator.resetConfiguration(); 81 PatternLayout layout = new PatternLayout("%r %-5p [%c{1}] %m%n"); 82 ConsoleAppender appender = new ConsoleAppender(layout); 83 BasicConfigurator.configure(appender); 84 file = System.getProperty("org.jboss.test.logfile"); 85 if (file != null) 86 { 87 FileAppender fileAppender = new FileAppender(layout, file); 88 BasicConfigurator.configure(fileAppender); 89 } 90 } 91 } 92 | Popular Tags |