1 16 17 package examples.subclass; 18 19 import org.apache.log4j.*; 20 import org.apache.log4j.spi.LoggerFactory; 21 import org.apache.log4j.xml.DOMConfigurator; 22 import examples.customLevel.XLevel; 23 import org.apache.log4j.PropertyConfigurator; 24 import org.apache.log4j.helpers.LogLog; 25 26 37 public class MyLoggerTest { 38 39 50 static public void main(String [] args) { 51 52 if(args.length == 0) { 53 Logger root = Logger.getRootLogger(); 57 Layout layout = new PatternLayout("%p [%t] %c (%F:%L) - %m%n"); 58 root.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT)); 59 } 60 else if(args.length == 1) { 61 if(args[0].endsWith("xml")) { 62 DOMConfigurator.configure(args[0]); 63 } else { 64 PropertyConfigurator.configure(args[0]); 65 } 66 } else { 67 usage("Incorrect number of parameters."); 68 } 69 try { 70 MyLogger c = (MyLogger) MyLogger.getLogger("some.cat"); 71 c.trace("Hello"); 72 c.debug("Hello"); 73 } catch(ClassCastException e) { 74 LogLog.error("Did you forget to set the factory in the config file?", e); 75 } 76 } 77 78 static 79 void usage(String errMsg) { 80 System.err.println(errMsg); 81 System.err.println("\nUsage: "+MyLogger.class.getName() + "[configFile]\n" 82 + " where *configFile* is an optional configuration file, "+ 83 "either in properties or XML format."); 84 System.exit(1); 85 } 86 } 87 | Popular Tags |