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