logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Sicker (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-424) JDBCAppender: Add support for data types other then String
Date Wed, 23 Jul 2014 16:15:40 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-424?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14071899#comment-14071899

Matt Sicker commented on LOG4J2-424:

There's a couple ways we can go about adding this feature. We can use JDBC metadata to do
some "automatic" type conversion. We can add another attribute to specify the type, but this
would also require the type conversion. Re-using the TypeConverter code from plugin configuration,
this shouldn't be too difficult. However, a logical next step would be making the TypeConverters
properly extensible.

As a related addition, an SQLXML column type could allow for use of the XmlLayout as well.
This would most likely require additions to the Column configuration element.

> JDBCAppender: Add support for data types other then String
> ----------------------------------------------------------
>                 Key: LOG4J2-424
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-424
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Appenders
>    Affects Versions: 2.0-beta9
>         Environment: All
>            Reporter: Tihomir Meščić
>            Assignee: Nick Williams
> I am using the JDBCAppender to log to a Postgresql database. I have a table (log_entries)
that's used for logging purposes. 
> One of the attributes is of type INTEGER. The attribute is something specific for our
application and we are using ThreadContext (MDC) to set the value of the parameter.
> Currently, log4j provides no support for integer type attributes in the Column element
of the JDBC appender configuration (the only types supported are string (default), timestamp
- isEventTimestamp flag and Clob - isClob flag).
> When using the default settings in the Column element of the JDBC appender, log4j will
create a prepared statement and try to set the value using the Statement.setString() method.
Of course, the JDBC driver throws an exception:
> Caused by: org.postgresql.util.PSQLException: ERROR: column "mn_type_d" is of type integer
but expression is of type character varying
>   Hint: You will need to rewrite or cast the expression.
> My appender configuration:
>     <JDBC name="jdbcAppender" tableName="log_entries">
>       <DriverManager url="jdbc:postgresql://" username="xxx" password="xxx"
>       <Column name="log_entries_id" literal="nextval('hibernate_sequence')" />
>       .....
>       <Column name="message" isUnicode="false" pattern="%message" />
>       <Column name="mn_type_d" isUnicode="false" pattern="%X{mn_type_d}" /> <--
this is of type integer in the DB but LOG4J tries to insert it as a String  -->
>     </JDBC>

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message