KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > component > Logger2LogKitManager


1 /*
2  * Copyright 1997-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 package org.apache.avalon.excalibur.component;
17
18 import org.apache.avalon.excalibur.logger.LogKitManager;
19 import org.apache.avalon.excalibur.logger.LoggerManager;
20 import org.apache.avalon.framework.logger.LogKit2AvalonLoggerAdapter;
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.log.Hierarchy;
23 import org.apache.log.LogTarget;
24 import org.apache.log.Priority;
25
26
27 /**
28  * An adapter between LogkitManager and LoggerManager.
29  *
30  * @deprecated ECM is no longer supported
31  *
32  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
33  * @version $Revision: 1.5 $ $Date: 2004/02/28 11:47:14 $
34  */

35 class Logger2LogKitManager
36     implements LogKitManager
37 {
38     private final Hierarchy m_hierarchy = new Hierarchy();
39     private final LoggerManager m_loggerManager;
40     
41     public Logger2LogKitManager( final LoggerManager loggerManager )
42     {
43         m_loggerManager = loggerManager;
44         final LogKit2AvalonLoggerAdapter target =
45             new LogKit2AvalonLoggerAdapter( loggerManager.getDefaultLogger() );
46         m_hierarchy.setDefaultLogTarget( target );
47     }
48     
49     public org.apache.log.Logger getLogger( final String JavaDoc categoryName )
50     {
51         final Logger logger =
52             m_loggerManager.getLoggerForCategory( categoryName );
53         final org.apache.log.Logger logkitLogger =
54             getHierarchy().getLoggerFor( categoryName );
55         final LogKit2AvalonLoggerAdapter target =
56             new LogKit2AvalonLoggerAdapter( logger );
57         logkitLogger.setLogTargets( new LogTarget[ ] { target } );
58         
59         if ( logger.isDebugEnabled() )
60         {
61             logkitLogger.setPriority( Priority.DEBUG );
62         }
63         else if ( logger.isInfoEnabled() )
64         {
65             logkitLogger.setPriority( Priority.INFO );
66         }
67         else if ( logger.isWarnEnabled() )
68         {
69             logkitLogger.setPriority( Priority.WARN );
70         }
71         else if ( logger.isErrorEnabled() )
72         {
73             logkitLogger.setPriority( Priority.ERROR );
74         }
75         else if ( logger.isFatalErrorEnabled() )
76         {
77             logkitLogger.setPriority( Priority.FATAL_ERROR );
78         }
79         
80         return logkitLogger;
81     }
82     
83     public Hierarchy getHierarchy()
84     {
85         return m_hierarchy;
86     }
87 }
88
Popular Tags