1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package examples.lf5.InitUsingLog4JProperties;
18
19 import org.apache.log4j.Logger;
20
21 import java.io.IOException;
22
23 /**
24 * This class is a simple example of how to use the LogFactor5 logging
25 * window.
26 *
27 * The LF5Appender is the primary class that enables logging to the
28 * LogFactor5 logging window. The simplest method of using this Appender
29 * is to add the following line to your log4j.properties file:
30 *
31 * log4j.appender.A1=org.apache.log4j.lf5.LF5Appender
32 *
33 * The log4j.properties file MUST be in you system classpath. If this file
34 * is in your system classpath, a static initializer in the Category class
35 * will load the file during class initialization. The LF5Appender will be
36 * added to the root category of the Category tree.
37 *
38 * Create a log4j.properties file and add this line to it, or add this line
39 * to your existing log4j.properties file. Run the example at the command line
40 * and explore the results!
41 *
42 * @author Brent Sprecher
43 */
44
45 // Contributed by ThoughtWorks Inc.
46
47 public class InitUsingLog4JProperties {
48 //--------------------------------------------------------------------------
49 // Constants:
50 //--------------------------------------------------------------------------
51
52 //--------------------------------------------------------------------------
53 // Protected Variables:
54 //--------------------------------------------------------------------------
55
56 //--------------------------------------------------------------------------
57 // Private Variables:
58 //--------------------------------------------------------------------------
59
60 private static Logger logger =
61 Logger.getLogger(InitUsingLog4JProperties.class);
62
63 //--------------------------------------------------------------------------
64 // Constructors:
65 //--------------------------------------------------------------------------
66
67 //--------------------------------------------------------------------------
68 // Public Methods:
69 //--------------------------------------------------------------------------
70
71 public static void main(String argv[]) {
72 // Add a bunch of logging statements ...
73 logger.debug("Hello, my name is Homer Simpson.");
74 logger.debug("Hello, my name is Lisa Simpson.");
75 logger.debug("Hello, my name is Marge Simpson.");
76 logger.debug("Hello, my name is Bart Simpson.");
77 logger.debug("Hello, my name is Maggie Simpson.");
78
79 logger.info("We are the Simpsons!");
80 logger.info("Mmmmmm .... Chocolate.");
81 logger.info("Homer likes chocolate");
82 logger.info("Doh!");
83 logger.info("We are the Simpsons!");
84
85 logger.warn("Bart: I am through with working! Working is for chumps!" +
86 "Homer: Son, I'm proud of you. I was twice your age before " +
87 "I figured that out.");
88 logger.warn("Mmm...forbidden donut.");
89 logger.warn("D'oh! A deer! A female deer!");
90 logger.warn("Truly, yours is a butt that won't quit." +
91 "- Bart, writing as Woodrow to Ms. Krabappel.");
92
93 logger.error("Dear Baby, Welcome to Dumpsville. Population: you.");
94 logger.error("Dear Baby, Welcome to Dumpsville. Population: you.",
95 new IOException("Dumpsville, USA"));
96 logger.error("Mr. Hutz, are you aware you're not wearing pants?");
97 logger.error("Mr. Hutz, are you aware you're not wearing pants?",
98 new IllegalStateException("Error !!"));
99
100
101 logger.fatal("Eep.");
102 logger.fatal("Mmm...forbidden donut.",
103 new SecurityException("Fatal Exception"));
104 logger.fatal("D'oh! A deer! A female deer!");
105 logger.fatal("Mmmmmm .... Chocolate.",
106 new SecurityException("Fatal Exception"));
107 }
108
109 //--------------------------------------------------------------------------
110 // Protected Methods:
111 //--------------------------------------------------------------------------
112
113 //--------------------------------------------------------------------------
114 // Private Methods:
115 //--------------------------------------------------------------------------
116
117 //--------------------------------------------------------------------------
118 // Nested Top-Level Classes or Interfaces:
119 //--------------------------------------------------------------------------
120
121 }