1 16 17 package org.apache.log4j.xml.test; 18 19 import org.apache.log4j.xml.DOMConfigurator; 20 import org.apache.log4j.Logger; 21 import org.apache.log4j.LogManager; 22 import org.apache.log4j.Level; 23 28 31 public class DOMTest { 32 static Logger cat = Logger.getLogger(DOMTest.class.getName()); 33 34 35 public 36 static 37 void main(String argv[]) { 38 39 if(argv.length == 1) 40 init(argv[0]); 41 else 42 Usage("Wrong number of arguments."); 43 44 test(); 45 } 46 47 static 48 void Usage(String msg) { 49 System.err.println(msg); 50 System.err.println( "Usage: java " + DOMTest.class.getName() + 51 " configFile"); 52 System.exit(1); 53 } 54 55 static 56 void init(String configFile) { 57 DOMConfigurator.configure(configFile); 58 } 59 60 static 61 void test() { 62 int i = -1; 63 Logger root = Logger.getRootLogger(); 64 65 cat.debug("Message " + ++i); 66 root.debug("Message " + i); 67 68 cat.info ("Message " + ++i); 69 root.info("Message " + i); 70 71 cat.warn ("Message " + ++i); 72 root.warn("Message " + i); 73 74 cat.error("Message " + ++i); 75 root.error("Message " + i); 76 77 cat.log(Level.FATAL, "Message " + ++i); 78 root.log(Level.FATAL, "Message " + i); 79 80 Exception e = new Exception ("Just testing"); 81 cat.debug("Message " + ++i, e); 82 root.debug("Message " + i, e); 83 84 cat.error("Message " + ++i, e); 85 root.error("Message " + i, e); 86 87 LogManager.shutdown(); 88 } 89 } 90 | Popular Tags |