KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > BasicConfigurator


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 // Contibutors: "Luke Blanshard" <Luke@quiq.com>
18
// "Mark DONSZELMANN" <Mark.Donszelmann@cern.ch>
19
// "Muly Oved" <mulyoved@hotmail.com>
20

21 package org.apache.log4j;
22
23
24 /**
25    Use this class to quickly configure the package.
26
27    <p>For file based configuration see {@link
28    PropertyConfigurator}. For XML based configuration see {@link
29    org.apache.log4j.xml.DOMConfigurator DOMConfigurator}.
30
31    @since 0.8.1
32    @author Ceki G&uuml;lc&uuml; */

33 public class BasicConfigurator {
34
35   protected BasicConfigurator() {
36   }
37
38   /**
39      Add a {@link ConsoleAppender} that uses {@link PatternLayout}
40      using the {@link PatternLayout#TTCC_CONVERSION_PATTERN} and
41      prints to <code>System.out</code> to the root category. */

42   static
43   public
44   void configure() {
45     Logger root = Logger.getRootLogger();
46     root.addAppender(new ConsoleAppender(
47            new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
48   }
49
50   /**
51      Add <code>appender</code> to the root category.
52      @param appender The appender to add to the root category.
53   */

54   static
55   public
56   void configure(Appender appender) {
57     Logger root = Logger.getRootLogger();
58     root.addAppender(appender);
59   }
60
61   /**
62      Reset the default hierarchy to its defaut. It is equivalent to
63      calling
64      <code>Category.getDefaultHierarchy().resetConfiguration()</code>.
65
66      See {@link Hierarchy#resetConfiguration()} for more details. */

67   public
68   static
69   void resetConfiguration() {
70     LogManager.resetConfiguration();
71   }
72 }
73
Popular Tags