JeonYB / log4jdbc-remix

Automatically exported from code.google.com/p/log4jdbc-remix
1 stars 0 forks source link

is there a way to completely disable guts of log4jdbc based on a configuration #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am profiling the app with log4jdbc-remix and I do see performance hit as all 
the jdbc calls are routed to spy and they do do the guts. I am looking for a 
way to configure in such a way that if that configuration is enabled then and 
only then log4jdbc-remix should do what it is suppose to do. In all other 
cases, it should just delegate the call to underlying dataSource. I was hoping 
that this is what it would do if I implement interface SpyLogDelegator and 
return false from the following method

  public boolean isJdbcLoggingEnabled() {
         if (I want jdbcremix to start participating) return yes
else return false;
   }   

However, I see that this method is not even getting called at  all!

could you please tell what I am doing wrong?

Deepak

Original issue reported on code.google.com by dsoma...@gmail.com on 1 Mar 2013 at 7:01

GoogleCodeExporter commented 8 years ago
I guess we can do something like

public class Log4jdbcProxyDataSource implements DataSource {
    @Override
    public Connection getConnection() throws SQLException 
    { 
            if (getLogFormatter().isJdbcLoggingEnabled()) {
                final Connection connection = realDataSource.getConnection();
             return new ConnectionSpy(connection,DriverSpy.getRdbmsSpecifics(connection)); 
           }
           else {
              return realDataSource.getConnection();
           }

    } 
}
do you see any problem with that?

Original comment by dsoma...@gmail.com on 1 Mar 2013 at 7:16

GoogleCodeExporter commented 8 years ago
once I changed the following methods FROM

  @Override
    public Connection getConnection() throws SQLException 
    { 
       final Connection connection = realDataSource.getConnection();
       return new ConnectionSpy(connection,DriverSpy.getRdbmsSpecifics(connection));
    }
    @Override
    public Connection getConnection(String username, String password) throws SQLException 
    { 
      final Connection connection = realDataSource.getConnection(username, password);
      return new ConnectionSpy(connection,DriverSpy.getRdbmsSpecifics(connection));
    }

TO

  @Override
    public Connection getConnection() throws SQLException 
    { 
            final Connection connection = realDataSource.getConnection();
            if (getLogFormatter().isJdbcLoggingEnabled()) {
                return new ConnectionSpy(connection,DriverSpy.getRdbmsSpecifics(connection));
            }
            else {
                return connection;
            }
    } 
    @Override
    public Connection getConnection(String username, String password) throws SQLException 
    { 
            final Connection connection = realDataSource.getConnection(username, password);
            if (getLogFormatter().isJdbcLoggingEnabled()) {
                return new ConnectionSpy(connection,DriverSpy.getRdbmsSpecifics(connection));
            }
            else {
                return connection;
            }
    }

I don't see log4jdbc in play when logging is turned off and profiler looks 
good. Could you please incorporate this change?

Original comment by dsoma...@gmail.com on 4 Mar 2013 at 6:41