Package org.apache.logging.log4j.core
Interface Appender
-
- All Superinterfaces:
LifeCycle
- All Known Implementing Classes:
AbstractAppender,AbstractDatabaseAppender,AbstractFileAppender,AbstractOutputStreamAppender,AbstractWriterAppender,AppenderAdapter.Adapter,AsyncAppender,ConsoleAppender,CountingNoOpAppender,FailoverAppender,FileAppender,HttpAppender,JdbcAppender,JeroMqAppender,JmsAppender,MemoryMappedFileAppender,NoSqlAppender,NullAppender,OutputStreamAppender,RandomAccessFileAppender,RewriteAppender,RollingFileAppender,RollingRandomAccessFileAppender,RoutingAppender,ScriptAppenderSelector,ServletAppender,SocketAppender,SyslogAppender,WriterAppender
public interface Appender extends LifeCycle
AppendsLogEvents. An Appender can contain aLayoutif applicable as well as anErrorHandler. Typical Appender implementations coordinate with an implementation ofAbstractManagerto handle external resources such as streams, connections, and other shared state. As Appenders are plugins, concrete implementations need to be annotated withPluginand need to provide a static factory method annotated withPluginFactory.Most core plugins are written using a related Manager class that handle the actual task of serializing a
LogEventto some output location. For instance, many Appenders can take advantage of theOutputStreamManagerclass.It is recommended that Appenders don't do any heavy lifting since there can be many instances of the class being used at any given time. When resources require locking (e.g., through
FileLock), it is important to isolate synchronized code to prevent concurrency issues.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringELEMENT_TYPEMain plugin element type for Appender plugins.static Appender[]EMPTY_ARRAYEmpty array.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidappend(LogEvent event)Logs a LogEvent using whatever logic this Appender wishes to use.ErrorHandlergetHandler()Gets theErrorHandlerused for handling exceptions.Layout<? extends java.io.Serializable>getLayout()Returns the Layout used by this Appender if applicable.java.lang.StringgetName()Gets the name of this Appender.booleanignoreExceptions()Some Appenders need to propagate exceptions back to the application.voidsetHandler(ErrorHandler handler)Sets theErrorHandlerused for handling exceptions.
-
-
-
Field Detail
-
ELEMENT_TYPE
static final java.lang.String ELEMENT_TYPE
Main plugin element type for Appender plugins.- Since:
- 2.6
- See Also:
- Constant Field Values
-
EMPTY_ARRAY
static final Appender[] EMPTY_ARRAY
Empty array.
-
-
Method Detail
-
append
void append(LogEvent event)
Logs a LogEvent using whatever logic this Appender wishes to use. It is typically recommended to use a bridge pattern not only for the benefits from decoupling an Appender from its implementation, but it is also handy for sharing resources which may require some form of locking.- Parameters:
event- The LogEvent.
-
getName
java.lang.String getName()
Gets the name of this Appender.- Returns:
- name, may be null.
-
getLayout
Layout<? extends java.io.Serializable> getLayout()
Returns the Layout used by this Appender if applicable.- Returns:
- the Layout for this Appender or
nullif none is configured.
-
ignoreExceptions
boolean ignoreExceptions()
Some Appenders need to propagate exceptions back to the application. WhenignoreExceptionsisfalsethe AppenderControl will allow the exception to percolate.- Returns:
trueif exceptions will be logged but not thrown,falseotherwise.
-
getHandler
ErrorHandler getHandler()
Gets theErrorHandlerused for handling exceptions.- Returns:
- the ErrorHandler for handling exceptions.
-
setHandler
void setHandler(ErrorHandler handler)
Sets theErrorHandlerused for handling exceptions.- Parameters:
handler- the ErrorHandler to use for handling exceptions.
-
-