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 21:55:55 GMT
Yes, something like that would be great, since this is not only an issue
with the Integer type, other data types
are also not supported. I've made my own implementation of the JDBC
appender that does exactly that. I don't
know what's the policy of the project, but I'll be happy to contribute the
code.

There is one more very nasty issue with the JDBC appender - the appender
will call setNString() method
on the PreparedStatement by default (this is the unicode version, available
in JDBC version 4). When using PostgreSQL
database with the latest JDBC driver this will cause an error when
inserting. It looked like a bug in log4j but then
(after a couple of hours of digging through log4j code) it turned out that
the JDBC driver for Postgres only partially implements JDBC
version 4 (it does not implement the setNString method) and nobody knows
when it'll implement the spec completely.
The fix was to set <Column isUnicode="false" in the appender configuration
- that way, the setString() method on the PreparedStatement
would be called.
IMHO, a more conservative, backwards compatible solution (non-Unicode)
should be the default...

Kind regards,
Tihomir



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

> On Wed, Oct 9, 2013 at 11:24 AM, Tihomir Meščić
> <tihomir.mescic@gmail.com> wrote:
> > 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
> > parameter.
> >
> > 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://10.28.10.32:5432/xxx"
> > 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>
>
> So maybe we need to be able to say:
>
> <Column name="mn_type_d" pattern="%X{mn_type_d}" type="INTEGER" />
>
> Where type is a name from java.sql.Types.
>
> Nick? Thoughts?
>
> Gary
>
> >
> >
> > Kind regards,
> > Tihomir
> >
> >
> > 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
> >>
> >
>
>
>
> --
> 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
>
>

Mime
View raw message