A few ideas all around extending JDBCAppender

1) override the getConnection() method.  In there you would contact your connection 
handler (you might have to write one) and grab the active connection.

2) add a new method like:
public setConnection(java.sql.Connection c) {
    connection = c;
}
Add call that every time you produce a transactional connection you want the 
JDBCAppender to use.  NB! you'll need to call it again with null after the transaction 
to reset it to default behavior.
You might want to fiddle with making that method static (and thus connection as well) 
so you don't have to find the actual appender instance.

3) place the Connection object into the message object sent to the Logger.  Then 
override getLogStatement(LoggingEvent event) in JDBCAppender, to pull out the 
Connection object, use that for the execution, and return the appropriate sql string.


I'd be happy to do some work/coding/design on this if you need help.

Kevin



Jeffrey Winter wrote:

> Has anyone come up with a mechanism that would allow a JDBCAppender to participate 
>in a transaction?
>
> I would like to use log4j as an "event logger" such that when specific updates are 
>made in the context of a transaction, an event is logged in a dedicated database 
>table.  However, if the transaction ultimately rolls-back, I'd like all of these log 
>entries to also rollback.
>
> The only way for this to happen is for the JDBCAppender to somehow have access to 
>the Connection upon which the transaction is occuring.  Is there anyway to pass that 
>sort of context into the Logger?


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to