Class AbstractDatabaseManager
java.lang.Object
org.apache.logging.log4j.core.appender.AbstractManager
org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
- All Implemented Interfaces:
Flushable,AutoCloseable
- Direct Known Subclasses:
JdbcDatabaseManager,NoSqlDatabaseManager
Manager that allows database appenders to have their configuration reloaded without losing events.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classImplementations should extend this class for passing data between the getManager method and the manager factory class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final Layout<? extends Serializable> private booleanFields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDatabaseManager(String name, int bufferSize) Deprecated.protectedAbstractDatabaseManager(String name, int bufferSize, Layout<? extends Serializable> layout) Deprecated.protectedAbstractDatabaseManager(String name, int bufferSize, Layout<? extends Serializable> layout, Configuration configuration) Constructs the base manager. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected abstract booleanCommits any active transaction (if applicable) and disconnects from the database (returns the connection to the connection pool).protected abstract voidConnects to the database and starts a transaction (if applicable).final voidflush()This method is called automatically when the buffer size reaches its maximum or at the beginning of a call toshutdown().protected static <M extends AbstractDatabaseManager,T extends AbstractDatabaseManager.AbstractFactoryData>
MgetManager(String name, T data, ManagerFactory<M, T> factory) Implementations should define their own getManager method and call this method from that to create or get existing managers.protected booleanfinal booleanIndicates whether the manager is currently connectedstartup()has been called andshutdown()has not been called).final booleanreleaseSub(long timeout, TimeUnit timeUnit) May be overridden by managers to perform processing while the manager is being released and the lock is held.final booleanshutdown()This method is called from theAbstractManager.close()method when the appender is stopped or the appender's manager is replaced.protected abstract booleanImplementations should implement this method to perform any proprietary disconnection / shutdown operations.final voidstartup()This method is called within the appender when the appender is started.protected abstract voidImplementations should implement this method to perform any proprietary startup operations.final StringtoString()final voidDeprecated.since 2.11.0 Usewrite(LogEvent, Serializable).final voidwrite(LogEvent event, Serializable serializable) This method manages buffering and writing of events.protected voidwriteInternal(LogEvent event) Deprecated.protected abstract voidwriteInternal(LogEvent event, Serializable serializable) Performs the actual writing of the event in an implementation-specific way.protected voidwriteThrough(LogEvent event, Serializable serializable) Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
Field Details
-
buffer
-
bufferSize
private final int bufferSize -
layout
-
running
private boolean running
-
-
Constructor Details
-
AbstractDatabaseManager
Deprecated.Constructs the base manager.- Parameters:
name- The manager name, which should include any configuration details that one might want to be able to reconfigure at runtime, such as database name, username, (hashed) password, etc.bufferSize- The size of the log event buffer.
-
AbstractDatabaseManager
@Deprecated protected AbstractDatabaseManager(String name, int bufferSize, Layout<? extends Serializable> layout) Deprecated.Constructs the base manager.- Parameters:
name- The manager name, which should include any configuration details that one might want to be able to reconfigure at runtime, such as database name, username, (hashed) password, etc.bufferSize- The size of the log event buffer.layout- the Appender-level layout.
-
AbstractDatabaseManager
protected AbstractDatabaseManager(String name, int bufferSize, Layout<? extends Serializable> layout, Configuration configuration) Constructs the base manager.- Parameters:
name- The manager name, which should include any configuration details that one might want to be able to reconfigure at runtime, such as database name, username, (hashed) password, etc.bufferSize- The size of the log event buffer.layout- the Appender-level layout.configuration- My configuration.
-
-
Method Details
-
getManager
protected static <M extends AbstractDatabaseManager,T extends AbstractDatabaseManager.AbstractFactoryData> M getManager(String name, T data, ManagerFactory<M, T> factory) Implementations should define their own getManager method and call this method from that to create or get existing managers.- Type Parameters:
M- The concrete manager type.T- The concreteAbstractDatabaseManager.AbstractFactoryDatatype.- Parameters:
name- The manager name, which should include any configuration details that one might want to be able to reconfigure at runtime, such as database name, username, (hashed) password, etc.data- The concrete instance ofAbstractDatabaseManager.AbstractFactoryDataappropriate for the given manager.factory- A factory instance for creating the appropriate manager.- Returns:
- a new or existing manager of the specified type and name.
-
buffer
-
commitAndClose
protected abstract boolean commitAndClose()Commits any active transaction (if applicable) and disconnects from the database (returns the connection to the connection pool). With buffering enabled, this is called when flushing the buffer completes, after the last call towriteInternal(org.apache.logging.log4j.core.LogEvent). With buffering disabled, this is called immediately after every invocation ofwriteInternal(org.apache.logging.log4j.core.LogEvent).- Returns:
- true if all resources were closed normally, false otherwise.
-
connectAndStart
protected abstract void connectAndStart()Connects to the database and starts a transaction (if applicable). With buffering enabled, this is called when flushing the buffer begins, before the first call towriteInternal(org.apache.logging.log4j.core.LogEvent). With buffering disabled, this is called immediately before every invocation ofwriteInternal(org.apache.logging.log4j.core.LogEvent). -
flush
public final void flush()This method is called automatically when the buffer size reaches its maximum or at the beginning of a call toshutdown(). It can also be called manually to flush events to the database. -
isBuffered
protected boolean isBuffered() -
isRunning
public final boolean isRunning()Indicates whether the manager is currently connectedstartup()has been called andshutdown()has not been called).- Returns:
trueif the manager is connected.
-
releaseSub
Description copied from class:AbstractManagerMay be overridden by managers to perform processing while the manager is being released and the lock is held. A timeout is passed for implementors to use as they see fit.- Overrides:
releaseSubin classAbstractManager- Parameters:
timeout- timeouttimeUnit- timeout time unit- Returns:
- true if all resources were closed normally, false otherwise.
-
shutdown
public final boolean shutdown()This method is called from theAbstractManager.close()method when the appender is stopped or the appender's manager is replaced. If it has not already been called, it callsshutdownInternal()and catches any exceptions it might throw.- Returns:
- true if all resources were closed normally, false otherwise.
-
shutdownInternal
Implementations should implement this method to perform any proprietary disconnection / shutdown operations. This method will never be called twice on the same instance, and it will only be called afterstartupInternal(). It is safe to throw any exceptions from this method. This method does not necessarily disconnect from the database for the same reasons outlined instartupInternal().- Returns:
- true if all resources were closed normally, false otherwise.
- Throws:
Exception
-
startup
public final void startup()This method is called within the appender when the appender is started. If it has not already been called, it callsstartupInternal()and catches any exceptions it might throw. -
startupInternal
Implementations should implement this method to perform any proprietary startup operations. This method will never be called twice on the same instance. It is safe to throw any exceptions from this method. This method does not necessarily connect to the database, as it is generally unreliable to connect once and use the same connection for hours.- Throws:
Exception
-
toString
-
write
Deprecated.since 2.11.0 Usewrite(LogEvent, Serializable).This method manages buffering and writing of events.- Parameters:
event- The event to write to the database.
-
write
This method manages buffering and writing of events.- Parameters:
event- The event to write to the database.serializable- Serializable event
-
writeInternal
Deprecated.Performs the actual writing of the event in an implementation-specific way. This method is called immediately fromwrite(LogEvent, Serializable)if buffering is off, or fromflush()if the buffer has reached its limit.- Parameters:
event- The event to write to the database.
-
writeInternal
Performs the actual writing of the event in an implementation-specific way. This method is called immediately fromwrite(LogEvent, Serializable)if buffering is off, or fromflush()if the buffer has reached its limit.- Parameters:
event- The event to write to the database.
-
writeThrough
-
AbstractDatabaseManager(String, int, Layout, Configuration).