Class AsyncJDBCAppender
- All Implemented Interfaces:
org.apache.logging.log4j.core.Appender,org.apache.logging.log4j.core.filter.Filterable,org.apache.logging.log4j.core.impl.LocationAware,org.apache.logging.log4j.core.LifeCycle,org.apache.logging.log4j.core.LifeCycle2
- Direct Known Subclasses:
JDBCRequestAppender
LogEvent data to the database table specified by the
LogTable property. If a target database is not specified the current
Windchill database is assumed.
For each LogEvent the following data items can be obtained:
- JVM_Id - Name of JVM process
- JVM_StartTime - Start time of JVM process (combination of this and JVM_Id should be unique)
- LE_Id - Id for the given log event (generated on demand)
- LE_Id_SeqNum - Sequence number portion of id for the given log event (generated on demand)
- LE_Timestamp - LogEvent timestamp
- LE_LoggerName - LogEvent logger name
- LE_Level - LogEvent level
- LE_ThreadName - LogEvent thread name
- LE_ThreadId - Id of thread from which logging event was passed to this appender (will match logging event thread unless misused)
- LE_Message - LogEvent message rendered as a string
- LE_Throwable - LogEvent throwable
- LE_ThrowableClass - Classname of LogEvent throwable
- LE_NDC - LogEvent NDC; only supplied when IncludeNDC process is true
- LE_MDC_{MDCKey} - LogEvent MDC entry value; only supplied when IncludeMDC property is true
- {AttributeItemNamePrefix}{AttributeName} - Value of given attribute (or item); only applies when LogEvent message object is
an
AttributeListProvider(e.g. anAttributeListWrapper),AttributeList,DynamicMBean, orCompositeData. Pseudo-attributes are created for each item within a CompositeData attribute of the form {AttributeItemNamePrefix}{AttributeName}.{itemName}. Similarly, pseudo-attributes of the form {AttributeItemNamePrefix}{AttributeName}.{index} [where index starts at 1] are created for each element of a collection like attribute [arrays, collections, and TabularData] if the attribute is listed in the ItemsToCollectionExpand property value. This pseudo-attribute creation is done recursively. Columns with _'s in place of the .'s will automatically be matched. AttributeItemNamePrefix is null by default, which is treated as an empty string.
All database operations are currently done from a single background thread, which has clear pros and cons. If the work load exceeds what this thread can keep up with, then the log events will either overflow the queue and be lost or the queue will block callers until it has room. On the other hand, the system will never be overtly taxed by this appender and it can use JDBC batch execution while ensuring maximum consistency between commits across tables in a given database.
Although one can target any database with a JDBC driver with this appender,
only Oracle and SQL Server (and only of the same versions otherwise
required by Windchill) have be tested and are thus supported at this time.
Supported API: true
Extendable: true
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidClearLogEventhandling backlog; exposed for such use cases as low-memory condition handling
Supported API: trueprotected StringdefaultRenderAsString(Object objectToRender) Produces a default string rendering of non-string data for which no better database mapping exists than to produce a string rendering.protected AttributeListexpandAttributeList(AttributeList origAttrList) ExpandsAttributeListto include additional attributes to represent individualCompositeDatafields.final voidflush()Flush batched records to database.final voidflushAll()Flush all batched records associated with this database connection.final StringGet accessor for prefix to apply to data item names for attributes; this is to allow one to ensure unique item names if one has an attribute with the same name as one of the JVM_* or LE_* data items.protected AttributeListgetAttributeList(Object message) final intGet accessor for interval of auto-flushing (in seconds).final StringGet accessor for severity of logging event that will automatically cause an immediate flush of data to the database
Supported API: truefinal intGet accessor for maximum number of batched records to accumulate prior to committing the data to the database.final intSize BLOB data is allowed to reach before it will be compressed.final booleanWhether appender should block when queue has reached its maximum backlog capacity.final StringGet accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.final intReturns currentLogEventhandling backlog.final StringGet accessor for attributes to obtain when message turns out to be aDynamicMBean.final StringGet accessor for comma-delimited list of item names to perform a collection-like expansion on.final StringGet accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed
Supported API: truefinal StringGet accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed
Supported API: truefinal StringGet accessor for name of database table to append to; defaults to name of appender
Supported API: truefinal intReturns maximum backlog allowed.final longReturns count of records which have overflowed the allowable backlog and been discarded
Supported API: truefinal StringGet accessor for database password used; defaults to that for Windchill itself where this can be accessed
Supported API: truefinal StringGet customer renderer map as string.final StringGet accessor for database storage time zone
Supported API: truestatic StringgetStringFromBlob(ResultSet results, int colNmb) Decodes a String from a column where it was previously encoded by this class and for whichisBlobType(int)returned true.static StringgetStringFromBlob(ResultSet results, String columnName) Decodes a String from a column where it was previously encoded by this class and for whichisBlobType(int)returned true.longDuration of time interval used to throttle output of Throwables in conjunction with ThrowableElideThreshold.intLength of Throwable message to preserve when eliding a Throwable as per ThrowableElideThreshold; a negative value implies no limit
Supported API: trueintThreshold for number of Throwables of any given Throwable class to log for any single logger within an interval duration specified by ThrowableElideIntervalSeconds before the Throwables should be elided to avoid excessive database storage requirements.final StringgetUser()Get accessor for database user used; defaults to that for Windchill itself where this can be accessed
Supported API: trueprotected booleanhandleOtherDataTypes(PreparedStatement preparedStatement, int bindIdx, Class<?> valueClass, Object value) Allow subclasses to handle additional data types in some manner other than storing the defaultRenderAsString() result if they so choose, e.g.static booleanisBlobType(int dataType) Whether a given SQL data type is considered a BLOB type by this class; this may include non-BLOB binary columns.final booleanGet accessor for whether log4j MDC (mapped diagnostic context) data should be included in output
Supported API: truefinal booleanGet accessor for whether log4j NDC (nested diagnostic context) data should be included in output
Supported API: truefinal voidpurge(int ageThresholdInDays) Deletes records older than specified threshold.final voidsetAttributeItemNamePrefix(String attributeItemNamePrefix) Set accessor for prefix to apply to data item names for attributes; this is to allow one to ensure unique item names if one has an attribute with the same name as one of the JVM_* or LE_* data items.final voidsetAutoFlushIntervalSeconds(int autoFlushIntervalSeconds) Set accessor for interval of auto-flushing (in seconds).final voidsetAutoFlushLevel(String autoFlushLevel) Set accessor for severity of logging event that will automatically cause an immediate flush of data to the database
Supported API: truefinal voidsetBatchSize(int batchSize) Set accessor for maximum number of batched records to accumulate prior to committing the data to the database.final voidsetBlobCompressionThreshold(int blobCompressionThreshold) Size BLOB data is allowed to reach before it will be compressed.final voidsetBlockRatherThanOverflow(boolean blockRatherThanOverflow) Whether appender should block when queue has reached its maximum backlog capacity.final voidsetColumnMap(String columnMap) Set accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.final voidsetDynamicMBeanAttrsToInclude(String dynamicMBeanAttrsToInclude) Set accessor for attributes to obtain when message turns out to be aDynamicMBean.final voidsetIncludeMDC(boolean includeMDC) Set accessor for whether log4j MDC (mapped diagnostic context) data should be included in output
Supported API: truefinal voidsetIncludeNDC(boolean includeNDC) Set accessor for whether log4j NDC (nested diagnostic context) data should be included in output
Supported API: truefinal voidsetItemsToCollectionExpand(String itemsToCollectionExpand) Set accessor for comma-delimited list of item names to perform a collection-like expansion on.final voidsetJDBCDriver(String jdbcDriver) Set accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed
Supported API: truefinal voidsetJDBCUrl(String jdbcUrl) Set accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed
Supported API: truefinal voidsetLogTable(String logTable) Set accessor for name of database table to append to; defaults to name of appender
Supported API: truefinal voidsetPassword(String password) Set accessor for database password used; defaults to that for Windchill itself where this can be accessed
Supported API: truefinal voidsetRendererMap(String rendererMap) Set customer renderer map from string.final voidsetStorageTimeZone(String timeZone) Set accessor for database storage time zone
Supported API: truevoidsetThrowableElideIntervalSeconds(long throwableElideIntervalSeconds) Duration of time interval used to throttle output of Throwables in conjunction with ThrowableElideThreshold.voidsetThrowableElideMessageLengthLimit(int throwableElideMessageLengthLimit) Length of Throwable message to preserve when eliding a Throwable as per ThrowableElideThreshold; a negative value implies no limit
Supported API: truevoidsetThrowableElideThreshold(int throwableElideThreshold) Threshold for number of Throwables of any given Throwable class to log for any single logger within an interval duration specified by ThrowableElideIntervalSeconds before the Throwables should be elided to avoid excessive database storage requirements.final voidSet accessor for database user used; defaults to that for Windchill itself where this can be accessed
Supported API: true
-
Method Details
-
getDynamicMBeanAttrsToInclude
Get accessor for attributes to obtain when message turns out to be aDynamicMBean. Obtains all readable attribute when null, which is generally not a good idea performance-wise.
Supported API: true -
setDynamicMBeanAttrsToInclude
Set accessor for attributes to obtain when message turns out to be aDynamicMBean. Obtains all readable attribute when null, which is generally not a good idea performance-wise.
Supported API: true -
isIncludeNDC
public final boolean isIncludeNDC()Get accessor for whether log4j NDC (nested diagnostic context) data should be included in output
Supported API: true -
setIncludeNDC
public final void setIncludeNDC(boolean includeNDC) Set accessor for whether log4j NDC (nested diagnostic context) data should be included in output
Supported API: true -
isIncludeMDC
public final boolean isIncludeMDC()Get accessor for whether log4j MDC (mapped diagnostic context) data should be included in output
Supported API: true -
setIncludeMDC
public final void setIncludeMDC(boolean includeMDC) Set accessor for whether log4j MDC (mapped diagnostic context) data should be included in output
Supported API: true -
getAttributeItemNamePrefix
Get accessor for prefix to apply to data item names for attributes; this is to allow one to ensure unique item names if one has an attribute with the same name as one of the JVM_* or LE_* data items.
Supported API: true -
setAttributeItemNamePrefix
Set accessor for prefix to apply to data item names for attributes; this is to allow one to ensure unique item names if one has an attribute with the same name as one of the JVM_* or LE_* data items.
Supported API: true -
getLogTable
Get accessor for name of database table to append to; defaults to name of appender
Supported API: true -
setLogTable
Set accessor for name of database table to append to; defaults to name of appender
Supported API: true -
getStorageTimeZone
Get accessor for database storage time zone
Supported API: true -
setStorageTimeZone
Set accessor for database storage time zone
Supported API: true -
getColumnMap
Get accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.
Supported API: true -
setColumnMap
Set accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.
Supported API: true -
getItemsToCollectionExpand
Get accessor for comma-delimited list of item names to perform a collection-like expansion on. Items to be expanded must be of either array, collection, or TabularData types. The expansion adds attributes of the form {AttributeItemNamePrefix}{AttributeName}.{index}, where index starts at 1. If the list contains "*", then all collection-like items are expanded.
Supported API: true -
setItemsToCollectionExpand
Set accessor for comma-delimited list of item names to perform a collection-like expansion on. Items to be expanded must be of either array, collection, or TabularData types. The expansion adds attributes of the form {AttributeItemNamePrefix}{AttributeName}.{index}, where index starts at 1. If the list contains "*", then all collection-like items are expanded.
Supported API: true -
getRendererMap
Get customer renderer map as string. SeeCustomRendererSupportfor more information.
Supported API: true -
setRendererMap
Set customer renderer map from string. SeeCustomRendererSupportfor more information.
Supported API: true -
getBatchSize
public final int getBatchSize()Get accessor for maximum number of batched records to accumulate prior to committing the data to the database.
Supported API: true -
setBatchSize
public final void setBatchSize(int batchSize) Set accessor for maximum number of batched records to accumulate prior to committing the data to the database.
Supported API: true -
getAutoFlushLevel
Get accessor for severity of logging event that will automatically cause an immediate flush of data to the database
Supported API: true -
setAutoFlushLevel
Set accessor for severity of logging event that will automatically cause an immediate flush of data to the database
Supported API: true -
getJDBCUrl
Get accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
setJDBCUrl
Set accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
getJDBCDriver
Get accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
setJDBCDriver
Set accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
getUser
Get accessor for database user used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
setUser
Set accessor for database user used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
getPassword
Get accessor for database password used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
setPassword
Set accessor for database password used; defaults to that for Windchill itself where this can be accessed
Supported API: true -
getAutoFlushIntervalSeconds
public final int getAutoFlushIntervalSeconds()Get accessor for interval of auto-flushing (in seconds). At this interval if some batched records have remained uncommitted for longer than this time period the batch will be committed to the database.
Supported API: true -
setAutoFlushIntervalSeconds
public final void setAutoFlushIntervalSeconds(int autoFlushIntervalSeconds) Set accessor for interval of auto-flushing (in seconds). At this interval if some batched records have remained uncommitted for longer than this time period the batch will be committed to the database.
Supported API: true -
getCurrentBacklog
public final int getCurrentBacklog()Returns currentLogEventhandling backlog.
Supported API: true -
getMaxBacklog
public final int getMaxBacklog()Returns maximum backlog allowed.
Supported API: true -
clearBacklog
public static void clearBacklog()ClearLogEventhandling backlog; exposed for such use cases as low-memory condition handling
Supported API: true -
getOverflowCount
public final long getOverflowCount()Returns count of records which have overflowed the allowable backlog and been discarded
Supported API: true -
getBlockRatherThanOverflow
public final boolean getBlockRatherThanOverflow()Whether appender should block when queue has reached its maximum backlog capacity.
Supported API: true -
setBlockRatherThanOverflow
public final void setBlockRatherThanOverflow(boolean blockRatherThanOverflow) Whether appender should block when queue has reached its maximum backlog capacity.
Supported API: true -
getBlobCompressionThreshold
public final int getBlobCompressionThreshold()Size BLOB data is allowed to reach before it will be compressed.
Supported API: true -
setBlobCompressionThreshold
public final void setBlobCompressionThreshold(int blobCompressionThreshold) Size BLOB data is allowed to reach before it will be compressed.
Supported API: true -
getThrowableElideThreshold
public int getThrowableElideThreshold()Threshold for number of Throwables of any given Throwable class to log for any single logger within an interval duration specified by ThrowableElideIntervalSeconds before the Throwables should be elided to avoid excessive database storage requirements. Non-positive values imply no limit.
Supported API: true -
setThrowableElideThreshold
public void setThrowableElideThreshold(int throwableElideThreshold) Threshold for number of Throwables of any given Throwable class to log for any single logger within an interval duration specified by ThrowableElideIntervalSeconds before the Throwables should be elided to avoid excessive database storage requirements. Non-positive values imply no limit.
Supported API: true -
getThrowableElideMessageLengthLimit
public int getThrowableElideMessageLengthLimit()Length of Throwable message to preserve when eliding a Throwable as per ThrowableElideThreshold; a negative value implies no limit
Supported API: true -
setThrowableElideMessageLengthLimit
public void setThrowableElideMessageLengthLimit(int throwableElideMessageLengthLimit) Length of Throwable message to preserve when eliding a Throwable as per ThrowableElideThreshold; a negative value implies no limit
Supported API: true -
getThrowableElideIntervalSeconds
public long getThrowableElideIntervalSeconds()Duration of time interval used to throttle output of Throwables in conjunction with ThrowableElideThreshold.
Supported API: true -
setThrowableElideIntervalSeconds
public void setThrowableElideIntervalSeconds(long throwableElideIntervalSeconds) Duration of time interval used to throttle output of Throwables in conjunction with ThrowableElideThreshold.
Supported API: true -
purge
Deletes records older than specified threshold.
Supported API: true- Throws:
SQLException
-
flush
public final void flush()Flush batched records to database.
Supported API: true -
flushAll
public final void flushAll()Flush all batched records associated with this database connection.
Supported API: true -
getAttributeList
-
expandAttributeList
ExpandsAttributeListto include additional attributes to represent individualCompositeDatafields.
Supported API: true -
isBlobType
public static boolean isBlobType(int dataType) Whether a given SQL data type is considered a BLOB type by this class; this may include non-BLOB binary columns.
Supported API: true -
getStringFromBlob
public static String getStringFromBlob(ResultSet results, int colNmb) throws SQLException, IOException Decodes a String from a column where it was previously encoded by this class and for whichisBlobType(int)returned true.
Supported API: true- Throws:
SQLExceptionIOException
-
getStringFromBlob
public static String getStringFromBlob(ResultSet results, String columnName) throws SQLException, IOException Decodes a String from a column where it was previously encoded by this class and for whichisBlobType(int)returned true.
Supported API: true- Throws:
SQLExceptionIOException
-
handleOtherDataTypes
protected boolean handleOtherDataTypes(PreparedStatement preparedStatement, int bindIdx, Class<?> valueClass, Object value) Allow subclasses to handle additional data types in some manner other than storing the defaultRenderAsString() result if they so choose, e.g. by "preparedStatement.setLong(bindIdx, value.asLong())". If the data is handled by this method, it should return true.
Supported API: true -
defaultRenderAsString
Produces a default string rendering of non-string data for which no better database mapping exists than to produce a string rendering.
Supported API: true
-