KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > lf5 > InitUsingLog4JProperties


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.InitUsingLog4JProperties;
17
18 import org.apache.log4j.Logger;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * This class is a simple example of how to use the LogFactor5 logging
24  * window.
25  *
26  * The LF5Appender is the primary class that enables logging to the
27  * LogFactor5 logging window. The simplest method of using this Appender
28  * is to add the following line to your log4j.properties file:
29  *
30  * log4j.appender.A1=org.apache.log4j.lf5.LF5Appender
31  *
32  * The log4j.properties file MUST be in you system classpath. If this file
33  * is in your system classpath, a static initializer in the Category class
34  * will load the file during class initialization. The LF5Appender will be
35  * added to the root category of the Category tree.
36  *
37  * Create a log4j.properties file and add this line to it, or add this line
38  * to your existing log4j.properties file. Run the example at the command line
39  * and explore the results!
40  *
41  * @author Brent Sprecher
42  */

43
44 // Contributed by ThoughtWorks Inc.
45

46 public class InitUsingLog4JProperties {
47     //--------------------------------------------------------------------------
48
// Constants:
49
//--------------------------------------------------------------------------
50

51     //--------------------------------------------------------------------------
52
// Protected Variables:
53
//--------------------------------------------------------------------------
54

55     //--------------------------------------------------------------------------
56
// Private Variables:
57
//--------------------------------------------------------------------------
58

59     private static Logger logger =
60             Logger.getLogger(InitUsingLog4JProperties.class);
61
62     //--------------------------------------------------------------------------
63
// Constructors:
64
//--------------------------------------------------------------------------
65

66     //--------------------------------------------------------------------------
67
// Public Methods:
68
//--------------------------------------------------------------------------
69

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

112     //--------------------------------------------------------------------------
113
// Private Methods:
114
//--------------------------------------------------------------------------
115

116     //--------------------------------------------------------------------------
117
// Nested Top-Level Classes or Interfaces:
118
//--------------------------------------------------------------------------
119

120 }
121
Popular Tags