KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > logger > logkit > LogKitLoggerHelper


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.logkit;
20
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.avalon.framework.logger.LogEnabled;
23 import org.apache.log.Hierarchy;
24
25
26 /**
27  * Tie this object to a LoggerManagerTee, give it the Hierachy
28  * that LogKitAdapter operates upon and it will substitute
29  * the ErrorHandler for the Hierarchy at the enableLogging() call.
30  *
31  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
32  * @version CVS $Revision: 1.3 $ $Date: 2004/03/10 13:54:51 $
33  * @since 4.0
34  */

35 public class LogKitLoggerHelper implements LogEnabled
36 {
37     /* The hierarchy to operate upon */
38     private final Hierarchy m_hierarchy;
39
40     /* Creates an instance of LogKitLoggerHelper. */
41     public LogKitLoggerHelper( final Hierarchy hierarchy )
42     {
43         if ( hierarchy == null ) throw new NullPointerException JavaDoc( "hierarchy" );
44         m_hierarchy = hierarchy;
45     }
46
47     /* The main work - creation of a custom ErrorHandler is done here. */
48     public void enableLogging( final Logger logger )
49     {
50          if ( logger == null ) throw new NullPointerException JavaDoc( "logger" );
51          final ErrorHandlerAdapter errorHandler = new ErrorHandlerAdapter( logger );
52          m_hierarchy.setErrorHandler( errorHandler );
53     }
54 }
55
Popular Tags