Class FailoverAppender
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilterable
org.apache.logging.log4j.core.appender.AbstractAppender
org.apache.logging.log4j.core.appender.FailoverAppender
- All Implemented Interfaces:
Appender
,Filterable
,LocationAware
,LifeCycle
,LifeCycle2
@Plugin(name="Failover",
category="Core",
elementType="appender",
printObject=true)
public final class FailoverAppender
extends AbstractAppender
The FailoverAppender will capture exceptions in an Appender and then route the event
to a different appender. Hopefully it is obvious that the Appenders must be configured
to not suppress exceptions for the FailoverAppender to work.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
AbstractAppender.Builder<B extends AbstractAppender.Builder<B>>
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Configuration
private static final int
private final List
<AppenderControl> private final String[]
private final long
private long
private AppenderControl
private final String
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
ConstructorsModifierConstructorDescriptionprivate
FailoverAppender
(String name, Filter filter, String primary, String[] failovers, int intervalMillis, Configuration config, boolean ignoreExceptions, Property[] properties) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Handle the Log event.private void
callAppender
(LogEvent event) static FailoverAppender
createAppender
(String name, String primary, String[] failovers, String retryIntervalSeconds, Configuration config, Filter filter, String ignore) Create a Failover Appender.private void
void
start()
Make the Filter available for use.toString()
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, 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 Details
-
DEFAULT_INTERVAL_SECONDS
private static final int DEFAULT_INTERVAL_SECONDS- See Also:
-
-
failovers
-
config
-
primary
-
failoverAppenders
-
intervalNanos
private final long intervalNanos -
nextCheckNanos
private volatile long nextCheckNanos
-
-
Constructor Details
-
FailoverAppender
-
-
Method Details
-
start
public void start()Description copied from class:AbstractFilterable
Make the Filter available for use.- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractFilterable
-
append
Handle the Log event.- Parameters:
event
- The LogEvent.
-
callAppender
-
failover
-
toString
- Overrides:
toString
in classAbstractAppender
-
createAppender
@PluginFactory public static FailoverAppender createAppender(@PluginAttribute("name") String name, @PluginAttribute("primary") String primary, @PluginElement("Failovers") String[] failovers, @PluginAliases("retryInterval") @PluginAttribute("retryIntervalSeconds") String retryIntervalSeconds, @PluginConfiguration Configuration config, @PluginElement("Filter") Filter filter, @PluginAttribute("ignoreExceptions") String ignore) Create a Failover Appender.- Parameters:
name
- The name of the Appender (required).primary
- The name of the primary Appender (required).failovers
- The name of one or more Appenders to fail over to (at least one is required).retryIntervalSeconds
- The retry interval in seconds.config
- The current Configuration (passed by the Configuration when the appender is created).filter
- A Filter (optional).ignore
- If"true"
(default) exceptions encountered when appending events are logged; otherwise they are propagated to the caller.- Returns:
- The FailoverAppender that was created.
-