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