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,AppenderAdapter.Adapter,AsyncAppender,CountingNoOpAppender,FailoverAppender,HttpAppender,JeroMqAppender,JmsAppender,NullAppender,RewriteAppender,RoutingAppender,ScriptAppenderSelector,ServletAppender
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 Classes Modifier and Type Class Description static 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 Modifier and Type Field Description private ErrorHandlerhandlerprivate booleanignoreExceptionsprivate Layout<? extends java.io.Serializable>layoutprivate java.lang.Stringname-
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
Constructors Modifier Constructor Description protectedAbstractAppender(java.lang.String name, Filter filter, Layout<? extends java.io.Serializable> layout)Deprecated.protectedAbstractAppender(java.lang.String name, Filter filter, Layout<? extends java.io.Serializable> layout, boolean ignoreExceptions)Deprecated.protectedAbstractAppender(java.lang.String name, Filter filter, Layout<? extends java.io.Serializable> layout, boolean ignoreExceptions, Property[] properties)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiderror(java.lang.String msg)Handle an error with a message using theErrorHandlerconfigured for this Appender.voiderror(java.lang.String msg, java.lang.Throwable t)Handle an error with a message and an exception using theErrorHandlerconfigured for this Appender.voiderror(java.lang.String msg, LogEvent event, java.lang.Throwable t)Handle an error with a message, exception, and a logging event, using theErrorHandlerconfigured for this Appender.ErrorHandlergetHandler()Returns the ErrorHandler, if any.Layout<? extends java.io.Serializable>getLayout()Returns the Layout for the appender.java.lang.StringgetName()Returns the name of the Appender.booleanignoreExceptions()Some appenders need to propagate exceptions back to the application.static intparseInt(java.lang.String s, int defaultValue)booleanrequiresLocation()voidsetHandler(ErrorHandler handler)The handler must be set before the appender is started.protected java.io.SerializabletoSerializable(LogEvent event)Serializes the given event using the appender's layout if present.java.lang.StringtoString()-
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
-
-
-
-
Field Detail
-
name
private final java.lang.String name
-
ignoreExceptions
private final boolean ignoreExceptions
-
layout
private final Layout<? extends java.io.Serializable> layout
-
handler
private ErrorHandler handler
-
-
Constructor Detail
-
AbstractAppender
@Deprecated protected AbstractAppender(java.lang.String name, Filter filter, Layout<? extends java.io.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(java.lang.String name, Filter filter, Layout<? extends java.io.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(java.lang.String name, Filter filter, Layout<? extends java.io.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 Detail
-
parseInt
public static int parseInt(java.lang.String s, int defaultValue)
-
requiresLocation
public boolean requiresLocation()
- Specified by:
requiresLocationin interfaceLocationAware
-
error
public void error(java.lang.String msg)
Handle an error with a message using theErrorHandlerconfigured for this Appender.- Parameters:
msg- The message.
-
error
public void error(java.lang.String msg, LogEvent event, java.lang.Throwable t)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
public void error(java.lang.String msg, java.lang.Throwable t)Handle an error with a message and an exception using theErrorHandlerconfigured for this Appender.- Parameters:
msg- The message.t- The Throwable.
-
getHandler
public ErrorHandler getHandler()
Returns the ErrorHandler, if any.- Specified by:
getHandlerin interfaceAppender- Returns:
- The ErrorHandler.
-
getLayout
public Layout<? extends java.io.Serializable> getLayout()
Returns the Layout for the appender.
-
getName
public java.lang.String 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
public void setHandler(ErrorHandler handler)
The handler must be set before the appender is started.- Specified by:
setHandlerin interfaceAppender- Parameters:
handler- The ErrorHandler to use.
-
toSerializable
protected java.io.Serializable toSerializable(LogEvent event)
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-