Class AbstractAppender
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilterable
org.apache.logging.log4j.core.appender.AbstractAppender
- All Implemented Interfaces:
Appender
,Filterable
,LocationAware
,LifeCycle
,LifeCycle2
- Direct Known Subclasses:
AbstractDatabaseAppender
,AbstractOutputStreamAppender
,AbstractWriterAppender
,AsyncAppender
,CountingNoOpAppender
,FailoverAppender
,HttpAppender
,JeroMqAppender
,JmsAppender
,KafkaAppender
,NullAppender
,RewriteAppender
,RoutingAppender
,ScriptAppenderSelector
,SmtpAppender
public abstract class AbstractAppender
extends AbstractFilterable
implements Appender, LocationAware
Abstract base class for Appenders. Although Appenders do not have to extend this class, doing so will simplify their
implementation.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
AbstractAppender.Builder<B extends AbstractAppender.Builder<B>>
Subclasses can extend this abstract Builder.Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
Field Summary
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
Fields inherited from interface org.apache.logging.log4j.core.Appender
ELEMENT_TYPE, EMPTY_ARRAY
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractAppender
(String name, Filter filter, Layout<? extends Serializable> layout) Deprecated.protected
AbstractAppender
(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions) Deprecated.protected
AbstractAppender
(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Handle an error with a message using theErrorHandler
configured for this Appender.void
Handle an error with a message and an exception using theErrorHandler
configured for this Appender.void
Handle an error with a message, exception, and a logging event, using theErrorHandler
configured for this Appender.Returns the ErrorHandler, if any.Layout<? extends Serializable>
Returns the Layout for the appender.getName()
Returns the name of the Appender.boolean
Some appenders need to propagate exceptions back to the application.static int
boolean
void
setHandler
(ErrorHandler handler) The handler must be set before the appender is started.protected Serializable
toSerializable
(LogEvent event) Serializes the given event using the appender's layout if present.toString()
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, start, stop, stop
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
Constructor Details
-
AbstractAppender
@Deprecated protected AbstractAppender(String name, Filter filter, Layout<? extends Serializable> layout) Deprecated.Constructor that defaults to suppressing exceptions.- Parameters:
name
- The Appender name.filter
- The Filter to associate with the Appender.layout
- The layout to use to format the event.
-
AbstractAppender
@Deprecated protected AbstractAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions) Deprecated.Constructor.- Parameters:
name
- The Appender name.filter
- The Filter to associate with the Appender.layout
- The layout to use to format the event.ignoreExceptions
- If true, exceptions will be logged and suppressed. If false errors will be logged and then passed to the application.
-
AbstractAppender
protected AbstractAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties) Constructor.- Parameters:
name
- The Appender name.filter
- The Filter to associate with the Appender.layout
- The layout to use to format the event.ignoreExceptions
- If true, exceptions will be logged and suppressed. If false errors will be logged and then passed to the application.- Since:
- 2.11.2
-
-
Method Details
-
parseInt
-
requiresLocation
public boolean requiresLocation()- Specified by:
requiresLocation
in interfaceLocationAware
-
error
Handle an error with a message using theErrorHandler
configured for this Appender.- Parameters:
msg
- The message.
-
error
Handle an error with a message, exception, and a logging event, using theErrorHandler
configured for this Appender.- Parameters:
msg
- The message.event
- The LogEvent.t
- The Throwable.
-
error
Handle an error with a message and an exception using theErrorHandler
configured for this Appender.- Parameters:
msg
- The message.t
- The Throwable.
-
getHandler
Returns the ErrorHandler, if any.- Specified by:
getHandler
in interfaceAppender
- Returns:
- The ErrorHandler.
-
getLayout
Returns the Layout for the appender. -
getName
Returns the name of the Appender. -
ignoreExceptions
public boolean ignoreExceptions()Some appenders need to propagate exceptions back to the application. WhenignoreExceptions
isfalse
the AppenderControl will allow the exception to percolate.- Specified by:
ignoreExceptions
in interfaceAppender
- Returns:
true
if exceptions will be logged but now thrown,false
otherwise.
-
setHandler
The handler must be set before the appender is started.- Specified by:
setHandler
in interfaceAppender
- Parameters:
handler
- The ErrorHandler to use.
-
toSerializable
Serializes the given event using the appender's layout if present.- Parameters:
event
- the event to serialize.- Returns:
- the serialized event or null if no layout is present.
-
toString
-
AbstractAppender(String, Filter, Layout, boolean, Property[])
.