org.apache.log4j.xml.examples
public class: XMLSample [javadoc |
source]
java.lang.Object
org.apache.log4j.xml.examples.XMLSample
This
example code shows how to
read an XML based configuration file using a DOM parser.
Sample XML files sample1.xml
and sample2.xml are provided.
Note that the log4j.dtd is not in the local directory.
It is found by the class loader.
| Field Summary |
|---|
| static Logger | cat | |
| Method from org.apache.log4j.xml.examples.XMLSample Detail: |
static void Usage(String msg) {
System.err.println(msg);
System.err.println( "Usage: java " + XMLSample.class.getName() +
"configFile");
System.exit(1);
}
|
static void init(String configFile) {
DOMConfigurator.configure(configFile);
}
|
public static void main(String[] argv) {
if(argv.length == 1)
init(argv[0]);
else
Usage("Wrong number of arguments.");
sample();
}
|
static void sample() {
int i = -1;
cat.debug("Message " + ++i);
cat.warn ("Message " + ++i);
cat.error("Message " + ++i);
Exception e = new Exception("Just testing");
cat.debug("Message " + ++i, e);
}
|