You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Frank Thompson <fo...@rogers.com> on 2005/05/11 19:30:37 UTC

PreparedStatementLogProxy log4j output with bind variables

Hello All,

I was wondering if there was a way to either request a change or if there
was a way to override the current logging output sent to log4j as shown
below:

>From PreparedStatementLogProxy.java

public Object invoke(Object proxy, Method method, Object[] params) throws
Throwable {
    try {
      if (EXECUTE_METHODS.contains(method.getName())) {
        if (log.isDebugEnabled()) {
          log.debug("{pstm-" + id + "} PreparedStatement: " +
removeBreakingWhitespace(sql));
          log.debug("{pstm-" + id + "} Parameters: " + getValueString());
          log.debug("{pstm-" + id + "} Types: " + getTypeString());
        }

  .
  .
  .


The invoke() method simply prints the prepared statement with no bind
variable substitution so the statement is printed with the embedded '?'
placeholders.  Is there a way to also include the statement as it would be
sent to the database backend as the actual string with bind variables
replaced.  If not is there a way that this Proxy could implement a SPI
interface and adapter that could be configured as a runtime class that
could have a custom Proxy implementation.

Otherwise as it stands I would have to modify the class and rebundle a
custom jar to change the log4j output ...

thanks
frank

Re: PreparedStatementLogProxy log4j output with bind variables

Posted by Brandon Goodin <br...@gmail.com>.
you won't get the parameters inline with the prepared statement. But,
you do get the parameter output when you configure log4j correctly.

log4j.logger.com.ibatis=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG

Brandon

On 5/13/05, Brice Ruth <bd...@gmail.com> wrote:
> You can use p6spy ... this will do what you want w/o needing to modify
> this behaviour.
> 
> Just google for it.
> 
> Brice
> 
> On 5/11/05, Frank Thompson <fo...@rogers.com> wrote:
> > Hello All,
> >
> > I was wondering if there was a way to either request a change or if there
> > was a way to override the current logging output sent to log4j as shown
> > below:
> >
> > From PreparedStatementLogProxy.java
> >
> > public Object invoke(Object proxy, Method method, Object[] params) throws
> > Throwable {
> >     try {
> >       if (EXECUTE_METHODS.contains(method.getName())) {
> >         if (log.isDebugEnabled()) {
> >           log.debug("{pstm-" + id + "} PreparedStatement: " +
> > removeBreakingWhitespace(sql));
> >           log.debug("{pstm-" + id + "} Parameters: " + getValueString());
> >           log.debug("{pstm-" + id + "} Types: " + getTypeString());
> >         }
> >
> >   .
> >   .
> >   .
> >
> > The invoke() method simply prints the prepared statement with no bind
> > variable substitution so the statement is printed with the embedded '?'
> > placeholders.  Is there a way to also include the statement as it would be
> > sent to the database backend as the actual string with bind variables
> > replaced.  If not is there a way that this Proxy could implement a SPI
> > interface and adapter that could be configured as a runtime class that
> > could have a custom Proxy implementation.
> >
> > Otherwise as it stands I would have to modify the class and rebundle a
> > custom jar to change the log4j output ...
> >
> > thanks
> > frank
> >
> 
> --
> Brice Ruth
> Software Engineer, Madison WI
>

Re: PreparedStatementLogProxy log4j output with bind variables

Posted by Brice Ruth <bd...@gmail.com>.
You can use p6spy ... this will do what you want w/o needing to modify
this behaviour.

Just google for it.

Brice

On 5/11/05, Frank Thompson <fo...@rogers.com> wrote:
> Hello All,
> 
> I was wondering if there was a way to either request a change or if there
> was a way to override the current logging output sent to log4j as shown
> below:
> 
> From PreparedStatementLogProxy.java
> 
> public Object invoke(Object proxy, Method method, Object[] params) throws
> Throwable {
>     try {
>       if (EXECUTE_METHODS.contains(method.getName())) {
>         if (log.isDebugEnabled()) {
>           log.debug("{pstm-" + id + "} PreparedStatement: " +
> removeBreakingWhitespace(sql));
>           log.debug("{pstm-" + id + "} Parameters: " + getValueString());
>           log.debug("{pstm-" + id + "} Types: " + getTypeString());
>         }
> 
>   .
>   .
>   .
> 
> The invoke() method simply prints the prepared statement with no bind
> variable substitution so the statement is printed with the embedded '?'
> placeholders.  Is there a way to also include the statement as it would be
> sent to the database backend as the actual string with bind variables
> replaced.  If not is there a way that this Proxy could implement a SPI
> interface and adapter that could be configured as a runtime class that
> could have a custom Proxy implementation.
> 
> Otherwise as it stands I would have to modify the class and rebundle a
> custom jar to change the log4j output ...
> 
> thanks
> frank
> 


-- 
Brice Ruth
Software Engineer, Madison WI