KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > xml > test > DOMTest


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 //import org.apache.log4j.xml.examples.ReportParserError;
24
//import org.apache.xerces.parsers.DOMParser;
25
//import java.io.FileInputStream;
26
//import org.xml.sax.InputSource;
27

28 /**
29    @author Ceki Gülcü
30 */

31 public class DOMTest {
32   static Logger cat = Logger.getLogger(DOMTest.class.getName());
33
34
35   public
36   static
37   void main(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc e = new Exception JavaDoc("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