Appender.java
  1  /*
  2   * Copyright 1999-2005 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  
 17  package org.apache.log4j;
 18  
 19  import org.apache.log4j.spi.Filter;
 20  import org.apache.log4j.spi.ErrorHandler;
 21  import org.apache.log4j.spi.LoggingEvent;
 22  
 23  /**
 24     Implement this interface for your own strategies for outputting log
 25     statements.
 26  
 27     @author Ceki Gülcü 
 28  */
 29  public interface Appender {
 30  
 31    /**
 32       Add a filter to the end of the filter list.
 33  
 34       @since 0.9.0
 35     */
 36    void addFilter(Filter newFilter);
 37  
 38    /**
 39       Returns the head Filter. The Filters are organized in a linked list
 40       and so all Filters on this Appender are available through the result.
 41       
 42       @return the head Filter or null, if no Filters are present
 43       @since 1.1
 44    */
 45    public
 46    Filter getFilter();
 47  
 48    /**
 49       Clear the list of filters by removing all the filters in it.
 50       
 51       @since 0.9.0
 52     */
 53    public
 54    void clearFilters();
 55  
 56    /**
 57       Release any resources allocated within the appender such as file
 58       handles, network connections, etc.
 59  
 60       <p>It is a programming error to append to a closed appender.
 61  
 62       @since 0.8.4
 63    */
 64    public
 65    void close();
 66    
 67    /**
 68       Log in <code>Appender</code> specific way. When appropriate,
 69       Loggers will call the <code>doAppend</code> method of appender
 70       implementations in order to log. */
 71    public
 72    void doAppend(LoggingEvent event);
 73  
 74  
 75    /**
 76       Get the name of this appender. The name uniquely identifies the
 77       appender.  */
 78    public
 79    String getName();
 80  
 81  
 82    /**
 83       Set the {@link ErrorHandler} for this appender.
 84  
 85       @since 0.9.0
 86     */
 87    public
 88    void setErrorHandler(ErrorHandler errorHandler);
 89  
 90    /**
 91       Returns the {@link ErrorHandler} for this appender.
 92  
 93       @since 1.1
 94     */
 95    public
 96    ErrorHandler getErrorHandler();
 97  
 98    /**
 99       Set the {@link Layout} for this appender.
100  
101       @since 0.8.1
102    */
103    public
104    void setLayout(Layout layout);
105  
106    /**
107       Returns this appenders layout.
108       
109       @since 1.1
110    */
111    public
112    Layout getLayout();
113    
114  
115    /**
116       Set the name of this appender. The name is used by other
117       components to identify this appender.
118  
119       @since 0.8.1
120    */
121    public
122    void setName(String name);
123  
124    /**
125       Configurators call this method to determine if the appender
126      requires a layout. If this method returns <code>true</code>,
127      meaning that layout is required, then the configurator will
128      configure an layout using the configuration information at its
129      disposal.  If this method returns <code>false</code>, meaning that
130      a layout is not required, then layout configuration will be
131      skipped even if there is available layout configuration
132      information at the disposal of the configurator..
133  
134       <p>In the rather exceptional case, where the appender
135       implementation admits a layout but can also work without it, then
136       the appender should return <code>true</code>.
137       
138       @since 0.8.4 */
139    public
140    boolean requiresLayout();
141  }