KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > lf5 > InitUsingXMLPropertiesFile


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 package examples.lf5.InitUsingXMLPropertiesFile;
17
18 import org.apache.log4j.Logger;
19 import org.apache.log4j.xml.DOMConfigurator;
20
21 import java.io.IOException JavaDoc;
22 import java.net.URL JavaDoc;
23
24 /**
25  * This is another simple example of how to use the LogFactor5
26  * logging console.
27  *
28  * To make this example work, ensure that the lf5.jar, lf5-license.jar
29  * and example.xml files are in your classpath. Once your classpath has
30  * been set up, you can run the example from the command line.
31  *
32  * @author Brent Sprecher
33  */

34
35 // Contributed by ThoughtWorks Inc.
36

37 public class InitUsingXMLPropertiesFile {
38     //--------------------------------------------------------------------------
39
// Constants:
40
//--------------------------------------------------------------------------
41

42     //--------------------------------------------------------------------------
43
// Protected Variables:
44
//--------------------------------------------------------------------------
45

46     //--------------------------------------------------------------------------
47
// Private Variables:
48
//--------------------------------------------------------------------------
49

50     private static Logger logger =
51             Logger.getLogger(InitUsingXMLPropertiesFile.class);
52
53     //--------------------------------------------------------------------------
54
// Constructors:
55
//--------------------------------------------------------------------------
56

57     //--------------------------------------------------------------------------
58
// Public Methods:
59
//--------------------------------------------------------------------------
60

61     public static void main(String JavaDoc argv[]) {
62         // Use a PropertyConfigurator to initialize from a property file.
63
String JavaDoc resource =
64                 "/examples/lf5/InitUsingXMLPropertiesFile/example.xml";
65         URL JavaDoc configFileResource =
66                 InitUsingXMLPropertiesFile.class.getResource(resource);
67         DOMConfigurator.configure(configFileResource.getFile());
68
69         // Add a bunch of logging statements ...
70
logger.debug("Hello, my name is Homer Simpson.");
71         logger.debug("Hello, my name is Lisa Simpson.");
72         logger.debug("Hello, my name is Marge Simpson.");
73         logger.debug("Hello, my name is Bart Simpson.");
74         logger.debug("Hello, my name is Maggie Simpson.");
75
76         logger.info("We are the Simpsons!");
77         logger.info("Mmmmmm .... Chocolate.");
78         logger.info("Homer likes chocolate");
79         logger.info("Doh!");
80         logger.info("We are the Simpsons!");
81
82         logger.warn("Bart: I am through with working! Working is for chumps!" +
83                 "Homer: Son, I'm proud of you. I was twice your age before " +
84                 "I figured that out.");
85         logger.warn("Mmm...forbidden donut.");
86         logger.warn("D'oh! A deer! A female deer!");
87         logger.warn("Truly, yours is a butt that won't quit." +
88                 "- Bart, writing as Woodrow to Ms. Krabappel.");
89
90         logger.error("Dear Baby, Welcome to Dumpsville. Population: you.");
91         logger.error("Dear Baby, Welcome to Dumpsville. Population: you.",
92                 new IOException JavaDoc("Dumpsville, USA"));
93         logger.error("Mr. Hutz, are you aware you're not wearing pants?");
94         logger.error("Mr. Hutz, are you aware you're not wearing pants?",
95                 new IllegalStateException JavaDoc("Error !!"));
96
97
98         logger.fatal("Eep.");
99         logger.fatal("Mmm...forbidden donut.",
100                 new SecurityException JavaDoc("Fatal Exception"));
101         logger.fatal("D'oh! A deer! A female deer!");
102         logger.fatal("Mmmmmm .... Chocolate.",
103                 new SecurityException JavaDoc("Fatal Exception"));
104     }
105
106     //--------------------------------------------------------------------------
107
// Protected Methods:
108
//--------------------------------------------------------------------------
109

110     //--------------------------------------------------------------------------
111
// Private Methods:
112
//--------------------------------------------------------------------------
113

114     //--------------------------------------------------------------------------
115
// Nested Top-Level Classes or Interfaces:
116
//--------------------------------------------------------------------------
117

118 }
119
Popular Tags