KickJava   Java API By Example, From Geeks To Geeks.

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


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.log.ErrorHandler;
23 import org.apache.log.Priority;
24 import org.apache.log.LogEvent;
25
26 /**
27  * This class adapts o.a.a.f.logger.Logger
28  * to the LogKit ErrorHandler interface.
29  *
30  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
31  * @version CVS $Revision: 1.3 $ $Date: 2004/03/10 13:54:51 $
32  * @since 4.0
33  */

34
35 public class ErrorHandlerAdapter implements ErrorHandler
36 {
37     private final Logger m_reliableLogger;
38
39     public ErrorHandlerAdapter( final Logger reliableLogger )
40     {
41        if ( reliableLogger == null )
42        {
43            throw new NullPointerException JavaDoc( "reliableLogger" );
44        }
45        m_reliableLogger = reliableLogger;
46     }
47
48     public void error( final String JavaDoc message, final Throwable JavaDoc throwable, final LogEvent event )
49     {
50         // let them know we're not OK
51
m_reliableLogger.fatalError( message, throwable );
52
53         // transmit the original error
54
final Priority p = event.getPriority();
55         final String JavaDoc nestedMessage = "nested log event: " + event.getMessage();
56
57         if ( p == Priority.DEBUG )
58         {
59             m_reliableLogger.debug( nestedMessage, event.getThrowable() );
60         }
61         else if ( p == Priority.INFO )
62         {
63             m_reliableLogger.info( nestedMessage, event.getThrowable() );
64         }
65         else if ( p == Priority.WARN )
66         {
67             m_reliableLogger.warn( nestedMessage, event.getThrowable() );
68         }
69         else if ( p == Priority.ERROR )
70         {
71             m_reliableLogger.error( nestedMessage, event.getThrowable() );
72         }
73         else if ( p == Priority.FATAL_ERROR)
74         {
75             m_reliableLogger.fatalError( nestedMessage, event.getThrowable() );
76         }
77         else
78         {
79             /** This just plainly can't happen :-)*/
80             m_reliableLogger.error( "unrecognized priority " + nestedMessage,
81                 event.getThrowable() );
82         }
83     }
84 }
85
Popular Tags