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
,LifeCycle
,LifeCycle2
- Direct Known Subclasses:
JdbcAppender
,NoSqlAppender
public abstract class AbstractDatabaseAppender<T extends AbstractDatabaseManager> extends AbstractAppender
-
-
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
-
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
AbstractDatabaseAppender(String name, Filter filter, boolean ignoreExceptions, T manager)
Instantiates the base appender.protected
AbstractDatabaseAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, T manager)
Instantiates the base appender.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(LogEvent event)
Logs a LogEvent using whatever logic this Appender wishes to use.Layout<LogEvent>
getLayout()
This always returnsnull
, as database appenders do not use a single layout.T
getManager()
Returns the underlying manager in use within this appender.protected void
replaceManager(T manager)
Replaces the underlying manager in use within this appender.void
start()
Make the Filter available for use.boolean
stop(long timeout, TimeUnit timeUnit)
Cleanup the Filter.-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getName, ignoreExceptions, parseInt, setHandler, toSerializable, toString
-
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, 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
-
-
-
-
Constructor Detail
-
AbstractDatabaseAppender
protected AbstractDatabaseAppender(String name, Filter filter, boolean ignoreExceptions, T manager)
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, 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.
-
-
Method Detail
-
getLayout
public final Layout<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
public final T getManager()
Returns the underlying manager in use within this appender.- Returns:
- the manager.
-
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
public boolean stop(long timeout, TimeUnit timeUnit)
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.
-
append
public final void append(LogEvent event)
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.
-
replaceManager
protected final void replaceManager(T manager)
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.
-
-