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
Nested ClassesModifier and TypeClassDescriptionstatic classAbstractAppender.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, LOGGERFields inherited from interface org.apache.logging.log4j.core.Appender
ELEMENT_TYPE, EMPTY_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractAppender(String name, Filter filter, Layout<? extends Serializable> layout) Deprecated.protectedAbstractAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions) Deprecated.protectedAbstractAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidHandle an error with a message using theErrorHandlerconfigured for this Appender.voidHandle an error with a message and an exception using theErrorHandlerconfigured for this Appender.voidHandle an error with a message, exception, and a logging event, using theErrorHandlerconfigured for this Appender.Returns the ErrorHandler, if any.Layout<? extends Serializable>Returns the Layout for the appender.getName()Returns the name of the Appender.booleanSome appenders need to propagate exceptions back to the application.static intbooleanvoidsetHandler(ErrorHandler handler) The handler must be set before the appender is started.protected SerializabletoSerializable(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, stopMethods 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:
requiresLocationin interfaceLocationAware
-
error
Handle an error with a message using theErrorHandlerconfigured for this Appender.- Parameters:
msg- The message.
-
error
Handle an error with a message, exception, and a logging event, using theErrorHandlerconfigured for this Appender.- Parameters:
msg- The message.event- The LogEvent.t- The Throwable.
-
error
Handle an error with a message and an exception using theErrorHandlerconfigured for this Appender.- Parameters:
msg- The message.t- The Throwable.
-
getHandler
Returns the ErrorHandler, if any.- Specified by:
getHandlerin 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. WhenignoreExceptionsisfalsethe AppenderControl will allow the exception to percolate.- Specified by:
ignoreExceptionsin interfaceAppender- Returns:
trueif exceptions will be logged but now thrown,falseotherwise.
-
setHandler
The handler must be set before the appender is started.- Specified by:
setHandlerin 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[]).