View Javadoc

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 implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.log4j.spi;
19  
20  import org.apache.log4j.Appender;
21  import org.apache.log4j.Logger;
22  
23  
24  /**
25     Appenders may delegate their error handling to
26     <code>ErrorHandlers</code>.
27  
28     <p>Error handling is a particularly tedious to get right because by
29     definition errors are hard to predict and to reproduce. 
30  
31  
32     <p>Please take the time to contact the author in case you discover
33     that errors are not properly handled. You are most welcome to
34     suggest new error handling policies or criticize existing policies.
35  
36  
37     @author Ceki G&uuml;lc&uuml;
38     
39  */
40  public interface ErrorHandler extends OptionHandler {
41  
42    /**
43       Add a reference to a logger to which the failing appender might
44       be attached to. The failing appender will be searched and
45       replaced only in the loggers you add through this method.
46  
47       @param logger One of the loggers that will be searched for the failing
48       appender in view of replacement.
49       
50       @since 1.2 */
51    void setLogger(Logger logger);
52  
53  
54    /**
55       Equivalent to the {@link #error(String, Exception, int,
56       LoggingEvent event)} with the the event parameteter set to
57       <code>null</code>.
58       
59    */
60    void error(String message, Exception e, int errorCode);
61  
62    /**
63       This method is normally used to just print the error message
64       passed as a parameter.       
65    */
66    void error(String message);
67  
68    /**
69       This method is invoked to handle the error.
70  
71       @param message The message assoicated with the error.
72       @param e The Exption that was thrown when the error occured.
73       @param errorCode The error code associated with the error. 
74       @param event The logging event that the failing appender is asked
75              to log.
76  
77       @since 1.2 */
78    void error(String message, Exception e, int errorCode, LoggingEvent event);
79    
80    /**
81       Set the appender for which errors are handled. This method is
82       usually called when the error handler is configured.
83       
84       @since 1.2 */
85    void setAppender(Appender appender);
86  
87    /**
88       Set the appender to falkback upon in case of failure.
89       
90       @since 1.2 */
91    void setBackupAppender(Appender appender);
92  }