Search code examples
jdbcpropertieslog4j2

log4j2 configuring ColumnMapping type using properties format


I want to provide type parameter for columnMapping, but type parameter is already taken to specify that I am working with columnMapping.

For now my configuration is

appender.message_appender.columnMappings[1].type = ColumnMapping
appender.message_appender.columnMappings[1].name = journal_id
appender.message_appender.columnMappings[1].type = java.lang.Integer # can't have two type parameters

I don't understand how to set type of columnMappings[1] to int.

In xml it could be achieved like this

    <Jdbc name="databaseAppender" tableName="dsLogEntry" ignoreExceptions="false">
      <DataSource jndiName="java:/comp/env/jdbc/TestDataSourceAppender" />
      <ColumnMapping name="journal_id" type="java.lang.Integer"/>
      <MessageLayout />
    </Jdbc>

Solution

  • Unfortunately that is not possible, since the .type suffix is already used to indicate the plugin type ("ColumnMapping") of the component.

    To be able to use the properties configuration the type attribute of ColumnMapping must be renamed. You should consider filing a bug report.

    Summarizing: you can define the type attribute on ColumnMapping using the more commonly used XML, JSON or YAML formats. The strict XML and properties format do not allow that.

    Edit: since version 2.21.0 (cf. release notes) you can use columnType instead of type to designate the SQL type of a column:

    appender.message_appender.columnMappings[1].type = ColumnMapping
    appender.message_appender.columnMappings[1].name = journal_id
    appender.message_appender.columnMappings[1].columnType = java.lang.Integer