Package wt.log4j.jmx

Class AsyncJDBCAppender

java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilterable
org.apache.logging.log4j.core.appender.AbstractAppender
wt.log4j.jmx.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

@Plugin(name="AsyncJDBCAppender", category="Core", elementType="appender", printObject=true) public class AsyncJDBCAppender extends org.apache.logging.log4j.core.appender.AbstractAppender
Sends 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. an AttributeListWrapper), AttributeList, DynamicMBean, or CompositeData. 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.
For each of these items if the database table has a corresponding column or if there is a mapping from the item name to such a column name defined by the ColumnMap property.

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 Type
    Method
    Description
    static void
    Clear LogEvent handling backlog; exposed for such use cases as low-memory condition handling

    Supported API: true
    protected String
    defaultRenderAsString(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 AttributeList
    Expands AttributeList to include additional attributes to represent individual CompositeData fields.
    final void
    Flush batched records to database.
    final void
    Flush all batched records associated with this database connection.
    final String
    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.
    protected AttributeList
    Derives AttributeList from log message object

    Supported API: true
    final int
    Get accessor for interval of auto-flushing (in seconds).
    final String
    Get accessor for severity of logging event that will automatically cause an immediate flush of data to the database

    Supported API: true
    final int
    Get accessor for maximum number of batched records to accumulate prior to committing the data to the database.
    final int
    Size BLOB data is allowed to reach before it will be compressed.
    final boolean
    Whether appender should block when queue has reached its maximum backlog capacity.
    final String
    Get accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.
    final int
    Returns current LogEvent handling backlog.
    final String
    Get accessor for attributes to obtain when message turns out to be a DynamicMBean.
    final String
    Get accessor for comma-delimited list of item names to perform a collection-like expansion on.
    final String
    Get accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed

    Supported API: true
    final String
    Get accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed

    Supported API: true
    final String
    Get accessor for name of database table to append to; defaults to name of appender

    Supported API: true
    final int
    Returns maximum backlog allowed.
    final long
    Returns count of records which have overflowed the allowable backlog and been discarded

    Supported API: true
    final String
    Get accessor for database password used; defaults to that for Windchill itself where this can be accessed

    Supported API: true
    final String
    Get customer renderer map as string.
    final String
    Get accessor for database storage time zone

    Supported API: true
    static String
    getStringFromBlob(ResultSet results, int colNmb)
    Decodes a String from a column where it was previously encoded by this class and for which isBlobType(int) returned true.
    static String
    getStringFromBlob(ResultSet results, String columnName)
    Decodes a String from a column where it was previously encoded by this class and for which isBlobType(int) returned true.
    long
    Duration of time interval used to throttle output of Throwables in conjunction with ThrowableElideThreshold.
    int
    Length of Throwable message to preserve when eliding a Throwable as per ThrowableElideThreshold; a negative value implies no limit

    Supported API: true
    int
    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 String
    Get accessor for database user used; defaults to that for Windchill itself where this can be accessed

    Supported API: true
    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.
    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.
    final boolean
    Get accessor for whether log4j MDC (mapped diagnostic context) data should be included in output

    Supported API: true
    final boolean
    Get accessor for whether log4j NDC (nested diagnostic context) data should be included in output

    Supported API: true
    final void
    purge(int ageThresholdInDays)
    Deletes records older than specified threshold.
    final void
    setAttributeItemNamePrefix(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 void
    setAutoFlushIntervalSeconds(int autoFlushIntervalSeconds)
    Set accessor for interval of auto-flushing (in seconds).
    final void
    setAutoFlushLevel(String autoFlushLevel)
    Set accessor for severity of logging event that will automatically cause an immediate flush of data to the database

    Supported API: true
    final void
    setBatchSize(int batchSize)
    Set accessor for maximum number of batched records to accumulate prior to committing the data to the database.
    final void
    setBlobCompressionThreshold(int blobCompressionThreshold)
    Size BLOB data is allowed to reach before it will be compressed.
    final void
    setBlockRatherThanOverflow(boolean blockRatherThanOverflow)
    Whether appender should block when queue has reached its maximum backlog capacity.
    final void
    setColumnMap(String columnMap)
    Set accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.
    final void
    setDynamicMBeanAttrsToInclude(String dynamicMBeanAttrsToInclude)
    Set accessor for attributes to obtain when message turns out to be a DynamicMBean.
    final void
    setIncludeMDC(boolean includeMDC)
    Set accessor for whether log4j MDC (mapped diagnostic context) data should be included in output

    Supported API: true
    final void
    setIncludeNDC(boolean includeNDC)
    Set accessor for whether log4j NDC (nested diagnostic context) data should be included in output

    Supported API: true
    final void
    setItemsToCollectionExpand(String itemsToCollectionExpand)
    Set accessor for comma-delimited list of item names to perform a collection-like expansion on.
    final void
    setJDBCDriver(String jdbcDriver)
    Set accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed

    Supported API: true
    final void
    setJDBCUrl(String jdbcUrl)
    Set accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed

    Supported API: true
    final void
    setLogTable(String logTable)
    Set accessor for name of database table to append to; defaults to name of appender

    Supported API: true
    final void
    setPassword(String password)
    Set accessor for database password used; defaults to that for Windchill itself where this can be accessed

    Supported API: true
    final void
    setRendererMap(String rendererMap)
    Set customer renderer map from string.
    final void
    Set accessor for database storage time zone

    Supported API: true
    void
    setThrowableElideIntervalSeconds(long throwableElideIntervalSeconds)
    Duration of time interval used to throttle output of Throwables in conjunction with ThrowableElideThreshold.
    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
    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.
    final void
    Set accessor for database user used; defaults to that for Windchill itself where this can be accessed

    Supported API: true

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • getDynamicMBeanAttrsToInclude

      public final String getDynamicMBeanAttrsToInclude()
      Get accessor for attributes to obtain when message turns out to be a DynamicMBean. Obtains all readable attribute when null, which is generally not a good idea performance-wise.

      Supported API: true
    • setDynamicMBeanAttrsToInclude

      public final void setDynamicMBeanAttrsToInclude(String dynamicMBeanAttrsToInclude)
      Set accessor for attributes to obtain when message turns out to be a DynamicMBean. 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

      public final String 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

      public final void setAttributeItemNamePrefix(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.

      Supported API: true
    • getLogTable

      public final String getLogTable()
      Get accessor for name of database table to append to; defaults to name of appender

      Supported API: true
    • setLogTable

      public final void setLogTable(String logTable)
      Set accessor for name of database table to append to; defaults to name of appender

      Supported API: true
    • getStorageTimeZone

      public final String getStorageTimeZone()
      Get accessor for database storage time zone

      Supported API: true
    • setStorageTimeZone

      public final void setStorageTimeZone(String timeZone)
      Set accessor for database storage time zone

      Supported API: true
    • getColumnMap

      public final String getColumnMap()
      Get accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.

      Supported API: true
    • setColumnMap

      public final void setColumnMap(String columnMap)
      Set accessor for string representing map from original item name to column name as comma-delimited itemName=columnName pairs.

      Supported API: true
    • getItemsToCollectionExpand

      public final String 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

      public final void setItemsToCollectionExpand(String itemsToCollectionExpand)
      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

      public final String getRendererMap()
      Get customer renderer map as string. See CustomRendererSupport for more information.

      Supported API: true
    • setRendererMap

      public final void setRendererMap(String rendererMap)
      Set customer renderer map from string. See CustomRendererSupport for 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

      public final String getAutoFlushLevel()
      Get accessor for severity of logging event that will automatically cause an immediate flush of data to the database

      Supported API: true
    • setAutoFlushLevel

      public final void setAutoFlushLevel(String autoFlushLevel)
      Set accessor for severity of logging event that will automatically cause an immediate flush of data to the database

      Supported API: true
    • getJDBCUrl

      public final String getJDBCUrl()
      Get accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed

      Supported API: true
    • setJDBCUrl

      public final void setJDBCUrl(String jdbcUrl)
      Set accessor for JDBC URL used; defaults to that for Windchill itself where this can be accessed

      Supported API: true
    • getJDBCDriver

      public final String getJDBCDriver()
      Get accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed

      Supported API: true
    • setJDBCDriver

      public final void setJDBCDriver(String jdbcDriver)
      Set accessor for JDBC driver used; defaults to that for Windchill itself where this can be accessed

      Supported API: true
    • getUser

      public final String getUser()
      Get accessor for database user used; defaults to that for Windchill itself where this can be accessed

      Supported API: true
    • setUser

      public final void setUser(String user)
      Set accessor for database user used; defaults to that for Windchill itself where this can be accessed

      Supported API: true
    • getPassword

      public final String getPassword()
      Get accessor for database password used; defaults to that for Windchill itself where this can be accessed

      Supported API: true
    • setPassword

      public final void setPassword(String password)
      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 current LogEvent handling backlog.

      Supported API: true
    • getMaxBacklog

      public final int getMaxBacklog()
      Returns maximum backlog allowed.

      Supported API: true
    • clearBacklog

      public static void clearBacklog()
      Clear LogEvent handling 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

      public final void purge(int ageThresholdInDays) throws SQLException
      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

      protected AttributeList getAttributeList(Object message)
      Derives AttributeList from log message object

      Supported API: true
    • expandAttributeList

      protected AttributeList expandAttributeList(AttributeList origAttrList)
      Expands AttributeList to include additional attributes to represent individual CompositeData fields.

      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 which isBlobType(int) returned true.

      Supported API: true
      Throws:
      SQLException
      IOException
    • 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 which isBlobType(int) returned true.

      Supported API: true
      Throws:
      SQLException
      IOException
    • 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

      protected String defaultRenderAsString(Object objectToRender)
      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