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 ofAbstractDatabaseManagerthis 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
Nested ClassesModifier and TypeClassDescriptionstatic classNested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State -
Field Summary
FieldsFields 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
ConstructorsModifierConstructorDescriptionprotectedAbstractDatabaseAppender(String name, Filter filter, boolean ignoreExceptions, T manager) Deprecated.protectedAbstractDatabaseAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties, T manager) Instantiates the base appender.protectedAbstractDatabaseAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, T manager) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidLogs a LogEvent using whatever logic this Appender wishes to use.This always returnsnull, as database appenders do not use a single layout.final TReturns the underlying manager in use within this appender.protected final voidreplaceManager(T manager) Replaces the underlying manager in use within this appender.final voidstart()Make the Filter available for use.booleanCleanup the Filter.Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toStringMethods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, 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
-
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- Iftrueexceptions encountered when appending events are logged; otherwise they are propagated to the caller.manager- The matchingAbstractDatabaseManagerimplementation.
-
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- Iftrueexceptions encountered when appending events are logged; otherwise they are propagated to the caller.manager- The matchingAbstractDatabaseManagerimplementation.
-
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- Iftrueexceptions encountered when appending events are logged; otherwise they are propagated to the caller.manager- The matchingAbstractDatabaseManagerimplementation.
-
-
Method Details
-
append
Description copied from interface:AppenderLogs 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:
getLayoutin interfaceAppender- Overrides:
getLayoutin 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:AbstractFilterableMake the Filter available for use.- Specified by:
startin interfaceLifeCycle- Overrides:
startin classAbstractFilterable
-
stop
Description copied from class:AbstractFilterableCleanup the Filter.- Specified by:
stopin interfaceLifeCycle2- Overrides:
stopin 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).