001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.log4j.spi; 019 020import org.apache.log4j.Level; 021import org.apache.log4j.Logger; 022import org.apache.log4j.helpers.LogLog; 023 024 025// Contibutors: Mathias Bogaert 026 027/** 028 RootLogger sits at the top of the logger hierachy. It is a 029 regular logger except that it provides several guarantees. 030 031 <p>First, it cannot be assigned a <code>null</code> 032 level. Second, since root logger cannot have a parent, the 033 {@link #getChainedLevel} method always returns the value of the 034 level field without walking the hierarchy. 035 036 @author Ceki Gülcü 037 038 */ 039public final class RootLogger extends Logger { 040 /** 041 The root logger names itself as "root". However, the root 042 logger cannot be retrieved by name. 043 */ 044 public RootLogger(Level level) { 045 super("root"); 046 setLevel(level); 047 } 048 049 /** 050 Return the assigned level value without walking the logger 051 hierarchy. 052 */ 053 public final Level getChainedLevel() { 054 return level; 055 } 056 057 /** 058 Setting a null value to the level of the root logger may have catastrophic 059 results. We prevent this here. 060 061 @since 0.8.3 */ 062 public final void setLevel(Level level) { 063 if (level == null) { 064 LogLog.error( 065 "You have tried to set a null level to root.", new Throwable()); 066 } else { 067 this.level = level; 068 } 069 } 070 071}