logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tihomir Meščić <tihomir.mes...@gmail.com>
Subject Re: Missing feature in the JDBC appender
Date Wed, 09 Oct 2013 15:24:56 GMT
Ok, my database (Postgresql) has a table (log_entries) that's used for
logging purposes.
One of the attributes is of type INTEGER.
In the new version of the app we are migrating to log4j version 2 (beta9)
and we want to
use the JDBCAppender that bundled with log4j. The INTEGER attribute is
something specific for our
application and we are using ThreadContext (MDC) to set the value of the

Currently, log4j provides no support for integer type attributes in the
Column element of the JDBC appender
configuration (the only things 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 excpetion:

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:

    <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  -->

Kind regards,

2013/10/9 Gary Gregory <garydgregory@gmail.com>

> Hi Tihomir,
> Can you be more descriptive please with a practical example?
> Gary
> On Wed, Oct 9, 2013 at 10:43 AM, Tihomir Meščić
> <tihomir.mescic@gmail.com> wrote:
> > Hi everyone,
> >
> > there is a missing feature in the JDBCAppender for log4j version 2, it
> does
> > not support data types
> > other than string, date and clob. So for example, if the table you are
> > trying to log to has an Integer
> > column, there is way to force log4j to insert it. I ended up writing my
> own
> > JDBC appender. I think
> > that this feature is very important and it should definitively be
> included
> > in the final version.
> >
> > Log4j version: 2.0.0-beta9
> >
> > Kind regards,
> > Tihomir
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message