KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > lf5 > InitUsingPropertiesFile


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.InitUsingPropertiesFile;
17
18 import org.apache.log4j.Logger;
19 import org.apache.log4j.PropertyConfigurator;
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  * The LF5Appender is the primary class that enables logging to the
29  * LogFactor5 logging window. If the following line is added to a properties
30  * file, the LF5Appender will be appended to the root category when
31  * the properties file is loaded:
32  *
33  * log4j.appender.A1=org.apache.log4j.lf5.LF5Appender
34  *
35  * To make this example work, you must ensure that the example.properties file
36  * is in your classpath.You can then run the example at the command line.
37  *
38  * @author Brent Sprecher
39  */

40
41 // Contributed by ThoughtWorks Inc.
42

43 public class InitUsingPropertiesFile {
44     //--------------------------------------------------------------------------
45
// Constants:
46
//--------------------------------------------------------------------------
47

48     //--------------------------------------------------------------------------
49
// Protected Variables:
50
//--------------------------------------------------------------------------
51

52     //--------------------------------------------------------------------------
53
// Private Variables:
54
//--------------------------------------------------------------------------
55

56     private static Logger logger =
57             Logger.getLogger(InitUsingPropertiesFile.class);
58
59     //--------------------------------------------------------------------------
60
// Constructors:
61
//--------------------------------------------------------------------------
62

63     //--------------------------------------------------------------------------
64
// Public Methods:
65
//--------------------------------------------------------------------------
66

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

116     //--------------------------------------------------------------------------
117
// Private Methods:
118
//--------------------------------------------------------------------------
119

120     //--------------------------------------------------------------------------
121
// Nested Top-Level Classes or Interfaces:
122
//--------------------------------------------------------------------------
123

124 }
125
Popular Tags