public class Log4jOverridableConfigurer extends Object implements org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.core.PriorityOrdered, org.springframework.context.ApplicationContextAware
dataSource: the data source for the database to connect to.
tableName: the table name that contains the Log4J configuration.
selectColumn: the column to select that contains the Log4J configuration.
whereColumn and whereValue: an optional column name and value to filter on if multiple rows would be returned where a single row is required.
To use an externally specified Log4J override configuration, configure the overrideResourceLocation (e.g. file:///tmp/myOverride.xml).
To use the default Log4J configuration, specify an internally bundled defaultResourceLocation (e.g. classpath:herd-log4j.xml).
Given the difficulty of initializing Log4J from a non-URI such as the database, the approach taken is to read the configuration from the database and copy it
to a temporary file on the file system and initializes Log4J from there. Then the database watchdog thread will re-read the configuration as specified in the
configuration itself and will update the temporary file. Since the interval for the local file being updated and the interval when Log4J monitors the file
for changes are different, the actual changes may be slightly delayed, but no longer than double the configured interval.| Modifier and Type | Class and Description |
|---|---|
protected class |
Log4jOverridableConfigurer.JdbcOperation<T>
An internally used helper class for simplifying database access through plain JDBC.
|
protected class |
Log4jOverridableConfigurer.Log4jDbWatchdog
An internally used watchdog thread that keeps querying the database to retrieve the Log4J configuration each time it wakes up.
|
| Constructor and Description |
|---|
Log4jOverridableConfigurer() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
convertClob(Clob clob)
Converts a CLOB to a string.
|
protected String |
getConfigurationFromResultSet(ResultSet resultSet,
String selectColumn)
Extracts the configuration from the given result set.
|
protected String |
getLog4JConfigurationFromDatabase()
Gets the Log4J override configuration from the database.
|
int |
getOrder() |
Object |
postProcessAfterInitialization(Object bean,
String beanName) |
Object |
postProcessBeforeInitialization(Object bean,
String beanName) |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setDataSource(DataSource dataSource)
Sets the data source to use when connecting to the database to get the Log4J override configuration.
|
void |
setDefaultResourceLocation(String defaultResourceLocation)
The default Log4J configuration location to use if the override location isn't found.
|
void |
setOverrideResourceLocation(String overrideResourceLocation)
Set the Log4J override configuration resource location to use.
|
void |
setRefreshIntervalSeconds(int refreshIntervalSeconds)
Sets the interval seconds for refreshing log4j configuration configuration.
|
void |
setSelectColumn(String selectColumn)
Sets the column to be selected (from the specified "tableName") that contains the Log4J database override configuration.
|
void |
setTableName(String tableName)
Sets the table name that contains the Log4J database override configuration.
|
void |
setWhereColumn(String whereColumn)
Sets the optional where column to filter on to determine which row to retrieve that contains the Log4J database override configuration.
|
void |
setWhereValue(String whereValue)
Sets the optional where clause value to filter on to determine which row to retrieve that contains the Log4J database override configuration.
|
public Object postProcessBeforeInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessororg.springframework.beans.BeansExceptionpublic Object postProcessAfterInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
postProcessAfterInitialization in interface org.springframework.beans.factory.config.BeanPostProcessororg.springframework.beans.BeansExceptionprotected String getLog4JConfigurationFromDatabase()
protected String getConfigurationFromResultSet(ResultSet resultSet, String selectColumn) throws SQLException
ResultSet was created by a SELECT statement on the underlying database table.
The selectColumn is the column that will be retrieved from the result set. Normally the contained value is directly returned. However, if it is of type
CLOB, text is extracted as string. This method was mostly obtained from the DatabaseConfiguration class.resultSet - the current ResultSetselectColumn - the selected column to obtain from the result set.SQLException - if an error occurs.protected String convertClob(Clob clob) throws SQLException
clob - the CLOB to be converted.SQLException - if an error occurs.public int getOrder()
getOrder in interface org.springframework.core.Orderedpublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic void setOverrideResourceLocation(String overrideResourceLocation)
overrideResourceLocation - the location.public void setDefaultResourceLocation(String defaultResourceLocation)
defaultResourceLocation - the default location.public void setTableName(String tableName)
tableName - the table name.public void setSelectColumn(String selectColumn)
selectColumn - the select column.public void setWhereColumn(String whereColumn)
whereColumn - the where column to filter on.public void setWhereValue(String whereValue)
whereValue - the where value to filter on.public void setDataSource(DataSource dataSource)
dataSource - the data source.public void setRefreshIntervalSeconds(int refreshIntervalSeconds)
refreshIntervalSeconds - the refresh interval seconds.Copyright © 2021. All rights reserved.