logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicholas Williams <nicho...@nicholaswilliams.net>
Subject Re: Log4j 2 - Not implemented method used in JDBC appender
Date Tue, 16 Jul 2013 15:43:51 GMT
There won't ALWAYS be a problem, but there will be performance concerns and
there could SOMETIMES be a problem. Since your columns are non-Unicode,
PostgreSQL (either the database engine or the JDBC driver) will convert the
Unicode Strings to whatever character set your columns are in when it
inserts the record. Having to convert the character set for all of this
data for every insert /will/ impact performance. How much it will impact I
couldn't say for sure; I suspect it will be very minor and not even
noticeable.

The only time there would be a problem is if a log message contains
characters not representable in the non-Unicode character set you are
using. Once inserted, these characters will look like garbage. Unless you
have a highly localized application and log user input that could be in
other languages, or you have written your logging messages in a language
other than English, you will probably not notice a problem. Unfortunately,
if you anticipate such characters being present in log messages, the only
way to guarantee that the data is properly stored is to have Unicode
database columns (NVARCHAR) and a compliant JDBC4 driver.

Nick

On Tue, Jul 16, 2013 at 8:24 AM, Betty User <usrbetty@gmail.com> wrote:

> Hi Nick,
>
> agreed, this issue is related to poor implementation of PostgreSQL
> JDBC 4. Unfortunately there is no way how to change PostgreSQL to
> another database.
>
> I tried it and it works with isUnicode="false". But event logs are in
> unicode, shouldn't be there some problem during saving unicode events
> messages with disabled unicode support?
>
> M.
>
> 2013/7/16 Nick Williams <nicholas@nicholaswilliams.net>:
> > Actually I need to correct myself:
> >
> > On Jul 16, 2013, at 7:57 AM, Nick Williams wrote:
> >
> >> M.,
> >>
> >> setNString() is part of JDBC 4.0, which came with Java 6. It sounds
> like you are using the postgresql-x.x-xxxx.jdbc3.jar JDBC driver, which was
> written for Java 4. Please download the latest JDBC driver
> postgresql-9.2-1003.jdbc4.jar (
> http://jdbc.postgresql.org/download/postgresql-9.2-1003.jdbc4.jar).
> However, you should note that PostgreSQL's website says the following:
> >>
> >>> Support for JDBC4 methods is not complete, but the majority of methods
> are implemented.
> >>
> >> So it's possible that even the latest driver is not fully JDBC 4.0
> compliant and won't support this method. In that case, there's nothing we
> can do about it.
> >
> > There is something you can do about it: don't use unicode columns. Look
> at the documentation for the JDBC Appender (
> http://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender)
> and scroll down to the "Column Parameters" table. Each String <Column> you
> define defaults to unicode (because unicode is the best way for storing
> Java unicode Strings). If you use the defaults (all String columns are
> unicode) then the database columns for your table must be NVARCHAR (not
> VARCHAR) and Log4j will use setNString. However, if you add
> isUnicode="false" to the String columns, Log4j will use setString (and your
> database columns must be VARCHAR, not NVARCHAR).
> >
> > To be clear, it's really best and most efficient to store these values
> unicode. However, if the latest PostgreSQL driver still does not support
> setNString (again, this is a "bad thing"), you can use isUnicode="false" to
> get around this.
> >
> >> PostgreSQL has had 7 years to implement a JDBC 4.0 driver; you'll need
> to complain to them. JDBC 4.1 came out two years ago and JDBC 4.2 comes out
> next March. I suppose it'll be ~2020 before they implement those. :-/
> >>
> >> Opinion Section: Based on my reading of PostgreSQL website, it doesn't
> sound like a very Java-friendly database to use if you want to use modern
> versions of Java. At least MySQL and Microsoft SQL Server support JDBC 4.0
> (which Log4j requires) though they still haven't implemented JDBC 4.1
> (which Log4j does not require). Only Oracle fully supports JDBC 4.1 right
> now (sad face).
> >>
> >> Nick
> >>
> >> On Jul 16, 2013, at 6:18 AM, Betty User wrote:
> >>
> >>> Hello,
> >>>
> >>> I am trying to log Log4j 2 events into PostgreSQL database via JDBC
> >>> appender with datasource (com.jolbox.bonecp.BoneCPDataSource).
> >>>
> >>> This data source uses JDBC driver for PostgreSQL
> >>> (postgresql-9.2-1003.jdbc4.jar) but there isn't implemented
> >>> method org.postgresql.jdbc4.Jdbc4PreparedStatement.setNString(int,
> String)
> >>> which is called from Log4j 2.
> >>>
> >>> Is there some another way how to use Log4J database appender with
> >>> PostgreSQL database?
> >>>
> >>> Thank you for suggestions how to solve this issue.
> >>>
> >>> M.
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message