KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > logger > decorator > OverrideDefaultDecorator


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
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package org.apache.avalon.excalibur.logger.decorator;
20
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.avalon.excalibur.logger.LoggerManager;
23
24 /**
25  * Overrides the value passed from getDefaultLogger().
26  *
27  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
28  * @version CVS $Revision: 1.3 $ $Date: 2004/03/10 13:54:50 $
29  * @since 4.0
30  */

31 public class OverrideDefaultDecorator extends LoggerManagerDecorator
32 {
33     /**
34      * The override value for getDefaultLogger() and for
35      * getLoggerForCategory(""), getLoggerForCategory( null );
36      */

37     private final Logger m_defaultLogger;
38
39     /**
40      * Creates an <code>OverrideDecorator</code> instance.
41      * @param defaultLogger <code>OverrideDecorator</code> is unique in that
42      * it won't tolerate a null extra argument: if this
43      * argument is <code>null</code> a NullPointerException will
44      * be thrown. This ensures that no logging surprises will occur.
45      */

46     public OverrideDefaultDecorator(
47             final LoggerManager loggerManager, final Logger defaultLogger )
48     {
49         super( loggerManager );
50         if ( defaultLogger == null ) throw new NullPointerException JavaDoc( "defaultLogger" );
51         m_defaultLogger = defaultLogger;
52     }
53
54     /**
55      * Return the Logger for the specified category.
56      */

57     public Logger getLoggerForCategory( final String JavaDoc categoryName )
58     {
59         if ( categoryName == null || categoryName.length() == 0 )
60         {
61             return m_defaultLogger;
62         }
63         else
64         {
65             return m_loggerManager.getLoggerForCategory( categoryName );
66         }
67     }
68
69     /**
70      * Return the default Logger. This is basically the same
71      * as getting the Logger for the "" category.
72      */

73     public Logger getDefaultLogger()
74     {
75         return m_defaultLogger;
76     }
77 }
78
Popular Tags