KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > spi > RootLogger


1 /*
2  * Copyright 1999,2004 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 package org.apache.log4j.spi;
18
19 import org.apache.log4j.*;
20 import org.apache.log4j.helpers.LogLog;
21
22
23 // Contibutors: Mathias Bogaert
24

25 /**
26    RootLogger sits at the top of the logger hierachy. It is a
27    regular logger except that it provides several guarantees.
28
29    <p>First, it cannot be assigned a <code>null</code>
30    level. Second, since root logger cannot have a parent, the
31    {@link #getChainedLevel} method always returns the value of the
32    level field without walking the hierarchy.
33
34    @author Ceki G&uuml;lc&uuml;
35
36  */

37 public final class RootLogger extends Logger {
38   /**
39      The root logger names itself as "root". However, the root
40      logger cannot be retrieved by name.
41   */

42   public RootLogger(Level level) {
43     super("root");
44     setLevel(level);
45   }
46
47   /**
48      Return the assigned level value without walking the logger
49      hierarchy.
50   */

51   public final Level getChainedLevel() {
52     return level;
53   }
54
55   /**
56      Setting a null value to the level of the root logger may have catastrophic
57      results. We prevent this here.
58
59      @since 0.8.3 */

60   public final void setLevel(Level level) {
61     if (level == null) {
62       LogLog.error(
63         "You have tried to set a null level to root.", new Throwable JavaDoc());
64     } else {
65       this.level = level;
66     }
67   }
68
69 }
70
Popular Tags