KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > logger > log4j > Log4JAdapter


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.log4j;
20
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.avalon.framework.logger.AbstractLogEnabled;
23 import org.apache.avalon.excalibur.logger.Log4JLogger;
24 import org.apache.avalon.excalibur.logger.LoggerManager;
25 import org.apache.log4j.spi.LoggerRepository;
26
27 /**
28  * This class sits on top of an existing Log4J Hierarchy
29  * and returns logger wrapping Log4J loggers.
30  *
31  * Attach PrefixDecorator and/or CachingDecorator if desired.
32  *
33  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
34  * @version CVS $Revision: 1.4 $ $Date: 2004/03/10 13:54:51 $
35  * @since 4.0
36  */

37 public class Log4JAdapter extends AbstractLogEnabled implements LoggerManager
38 {
39     protected final LoggerRepository m_hierarchy;
40
41     public Log4JAdapter( final LoggerRepository hierarchy )
42     {
43         if ( hierarchy == null ) throw new NullPointerException JavaDoc( "hierarchy" );
44         m_hierarchy = hierarchy;
45     }
46
47     /**
48      * Return the Logger for the specified category.
49      * Log4J probably won't like the "" category name
50      * so we shall better return its getRootLogger() instead.
51      */

52     public Logger getLoggerForCategory( final String JavaDoc categoryName )
53     {
54         if ( null == categoryName || categoryName.length() == 0 )
55         {
56             return getDefaultLogger();
57         }
58         else
59         {
60             return new Log4JLogger( m_hierarchy.getLogger( categoryName ) );
61         }
62     }
63
64     /**
65      * Return the default Logger. This is basically the same
66      * as getting the Logger for the "" category.
67      */

68     public Logger getDefaultLogger()
69     {
70         return new Log4JLogger( m_hierarchy.getRootLogger() );
71     }
72 }
73
Popular Tags