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:49:25 GMT
You can certainly implement your own appender. Reading the Log4j
documentation and perusing the source code should help you get started. You
cannot, however, create a custom implementation of inserting messages into
the database. If you have a suggestion of how the JDBC appender could be
improved, we will certainly consider them. Patches are always welcome.

You said, "After all, there is no problem with inserting Unicode strings
into a PostgreSQL database via PostgreSQL JDBC 4 driver." I'm not sure
exactly what you meant. Did you mean that you currently have NVARCHAR
columns that you are inserting Unicode data into using
PreparedStatement.setString() elsewhere in your application? If so, then
you probably won't have any problems. If this is working and you are
successfully inserting non-Latin Unicode characters into NVARCHAR columns
using setString(), that means that the PostgreSQL driver is detecting the
column type and keeping the data Unicode during the entire process. In this
case, your log messages will still be stored correctly as long as the
columns are NVARCHAR.

Hope this helps.

Nick

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

> One more question if I can - Is there some way or reason to implement
> own appender and process Log4J messages in my way? After all, there is
> no problem with inserting unicode strings into a PostgreSQL database
> via PostgreSQL JDBC 4 driver (or com.jolbox.bonecp.BoneCPDataSource
> datasource in my case). If is it possible to have a custom
> implementation of inserting messages into database, the problem will
> be solved. I'll check it.
>
> 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