Class AbstractDatabaseAppender<T extends AbstractDatabaseManager>
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.db.AbstractDatabaseAppender<T>
- Type Parameters:
T
- Specifies which type ofAbstractDatabaseManager
this Appender requires.
- All Implemented Interfaces:
Appender
,Filterable
,LocationAware
,LifeCycle
,LifeCycle2
- Direct Known Subclasses:
JdbcAppender
,NoSqlAppender
public abstract class AbstractDatabaseAppender<T extends AbstractDatabaseManager>
extends AbstractAppender
An abstract Appender for writing events to a database of some type, be it relational or NoSQL. All database appenders
should inherit from this base appender.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
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
AbstractDatabaseAppender
(String name, Filter filter, boolean ignoreExceptions, T manager) Deprecated.protected
AbstractDatabaseAppender
(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties, T manager) Instantiates the base appender.protected
AbstractDatabaseAppender
(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, T manager) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Logs a LogEvent using whatever logic this Appender wishes to use.This always returnsnull
, as database appenders do not use a single layout.final T
Returns the underlying manager in use within this appender.protected final void
replaceManager
(T manager) Replaces the underlying manager in use within this appender.final void
start()
Make the Filter available for use.boolean
Cleanup the Filter.Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, 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_RECONNECT_INTERVAL_MILLIS
public static final int DEFAULT_RECONNECT_INTERVAL_MILLIS- See Also:
-
-
Constructor Details
-
AbstractDatabaseAppender
@Deprecated protected AbstractDatabaseAppender(String name, Filter filter, boolean ignoreExceptions, T manager) Deprecated.Instantiates the base appender.- Parameters:
name
- The appender name.filter
- The filter, if any, to use.ignoreExceptions
- Iftrue
exceptions encountered when appending events are logged; otherwise they are propagated to the caller.manager
- The matchingAbstractDatabaseManager
implementation.
-
AbstractDatabaseAppender
protected AbstractDatabaseAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties, T manager) Instantiates the base appender.- Parameters:
name
- The appender name.filter
- The filter, if any, to use.layout
- The layout to use to format the event.ignoreExceptions
- Iftrue
exceptions encountered when appending events are logged; otherwise they are propagated to the caller.manager
- The matchingAbstractDatabaseManager
implementation.
-
AbstractDatabaseAppender
@Deprecated protected AbstractDatabaseAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, T manager) Deprecated.Instantiates the base appender.- Parameters:
name
- The appender name.filter
- The filter, if any, to use.layout
- The layout to use to format the event.ignoreExceptions
- Iftrue
exceptions encountered when appending events are logged; otherwise they are propagated to the caller.manager
- The matchingAbstractDatabaseManager
implementation.
-
-
Method Details
-
append
Description copied from interface:Appender
Logs a LogEvent using whatever logic this Appender wishes to use. It is typically recommended to use a bridge pattern not only for the benefits from decoupling an Appender from its implementation, but it is also handy for sharing resources which may require some form of locking.- Parameters:
event
- The LogEvent.
-
getLayout
This always returnsnull
, as database appenders do not use a single layout. The JPA and NoSQL appenders do not use a layout at all. The JDBC appender has a layout-per-column pattern.- Specified by:
getLayout
in interfaceAppender
- Overrides:
getLayout
in classAbstractAppender
- Returns:
null
.
-
getManager
Returns the underlying manager in use within this appender.- Returns:
- the manager.
-
replaceManager
Replaces the underlying manager in use within this appender. This can be useful for manually changing the way log events are written to the database without losing buffered or in-progress events. The existing manager is released only after the new manager has been installed. This method is thread-safe.- Parameters:
manager
- The new manager to install.
-
start
public final void start()Description copied from class:AbstractFilterable
Make the Filter available for use.- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractFilterable
-
stop
Description copied from class:AbstractFilterable
Cleanup the Filter.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in classAbstractFilterable
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
AbstractDatabaseAppender(String, Filter, Layout, boolean, Property[], AbstractDatabaseManager)
.