1 16 17 package org.apache.log4j.xml.examples; 18 19 import org.apache.log4j.xml.DOMConfigurator; 20 import org.apache.log4j.Logger; 21 import java.net.*; 22 23 38 public class XMLSample { 39 40 static Logger cat = Logger.getLogger(XMLSample.class); 41 42 public 43 static 44 void main(String argv[]) { 45 46 if(argv.length == 1) 47 init(argv[0]); 48 else 49 Usage("Wrong number of arguments."); 50 sample(); 51 } 52 53 static 54 void Usage(String msg) { 55 System.err.println(msg); 56 System.err.println( "Usage: java " + XMLSample.class.getName() + 57 "configFile"); 58 System.exit(1); 59 } 60 61 static 62 void init(String configFile) { 63 DOMConfigurator.configure(configFile); 64 } 65 66 static 67 void sample() { 68 int i = -1; 69 Logger root = Logger.getRootLogger(); 70 cat.debug("Message " + ++i); 71 cat.warn ("Message " + ++i); 72 cat.error("Message " + ++i); 73 Exception e = new Exception ("Just testing"); 74 cat.debug("Message " + ++i, e); 75 } 76 } 77 | Popular Tags |