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:
AbstractOutputStreamAppender
,AbstractWriterAppender
,AppenderAdapter.Adapter
,AsyncAppender
,CountingNoOpAppender
,FailoverAppender
,HttpAppender
,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 Classes Modifier and Type Class Description static 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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
error(String msg)
Handle an error with a message using theErrorHandler
configured for this Appender.void
error(String msg, Throwable t)
Handle an error with a message and an exception using theErrorHandler
configured for this Appender.void
error(String msg, LogEvent event, Throwable t)
Handle an error with a message, exception, and a logging event, using theErrorHandler
configured for this Appender.ErrorHandler
getHandler()
Returns the ErrorHandler, if any.Layout<? extends Serializable>
getLayout()
Returns the Layout for the appender.String
getName()
Returns the name of the Appender.boolean
ignoreExceptions()
Some appenders need to propagate exceptions back to the application.static int
parseInt(String s, int defaultValue)
boolean
requiresLocation()
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.String
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 Detail
-
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 Detail
-
parseInt
public static int parseInt(String s, int defaultValue)
-
requiresLocation
public boolean requiresLocation()
- Specified by:
requiresLocation
in interfaceLocationAware
-
error
public void error(String msg)
Handle an error with a message using theErrorHandler
configured for this Appender.- Parameters:
msg
- The message.
-
error
public void error(String msg, LogEvent event, Throwable t)
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
public void error(String msg, Throwable t)
Handle an error with a message and an exception using theErrorHandler
configured for this Appender.- Parameters:
msg
- The message.t
- The Throwable.
-
getHandler
public ErrorHandler getHandler()
Returns the ErrorHandler, if any.- Specified by:
getHandler
in interfaceAppender
- Returns:
- The ErrorHandler.
-
getLayout
public Layout<? extends Serializable> getLayout()
Returns the Layout for the appender.
-
getName
public String 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
public void setHandler(ErrorHandler handler)
The handler must be set before the appender is started.- Specified by:
setHandler
in interfaceAppender
- Parameters:
handler
- The ErrorHandler to use.
-
toSerializable
protected 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.
-
-