Hi Matt, 

Feel free to dig in, I'll be in and out this long weekends. 

Gary

<div>-------- Original message --------</div><div>From: Matt Sicker 
<[email protected]> </div><div>Date:08/29/2014  14:16  (GMT-05:00) 
</div><div>To: Log4J Developers List <[email protected]> 
</div><div>Subject: Re: Playing nice with JDBC </div><div>
</div>I still have a patch that has the work Bruce and I did with that. We have 
a log4j-streams module for that. It's also in a branch somewhere, but I've had 
to convert it into a patch due to divergence from the trunk. I'll make a new 
git branch or something later tonight.


On 29 August 2014 12:36, Gary Gregory <[email protected]> wrote:
Hi All,

In am now developing some fancy JDBC proprietary do-hicky at work.

In JDBC, you log to a java.io.PrintWriter like this:

// for all drivers
DriverManager.setLogWriter(printWriter);

// for a specific driver (if that driver support it).
dataSource.setLogWriter(printWriter);

I want logging to go to Log4j 2. Granted, I've got no control with levels but 
at least I could give it a (single) level (see below) and, as usual, if I want 
the target to be the console or a file and do rollovers and such.

I could see wrapping a PW and then giving that to JDBC and Log4j somehow:

log4jPw = new Log4jPrintWriter(logger, Level.DEBUG);

... someLog4jObject.addEventSource(log4jPw);

DriverManager.setLogWriter(log4jPw);
// or
dataSource.setLogWriter(log4jPw);

The PW would buffer until it gets a println() or the buffer reaches some size 
limit, then turns its buffer into log event.

Also, JDBC 4.1 in Java 7 has some integration with JUL with 
javax.sql.CommonDataSource.getParentLogger() but each driver has to support 
that.

My requirements look like a perfect match with log4j2-547 and it looks like 
Bruce put a lot of work in there.

So I am going to experiment to bring that code base in.

Thoughts?

Gary

-- 
E-Mail: [email protected] | [email protected] 
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



-- 
Matt Sicker <[email protected]>

Reply via email to