Open GoogleCodeExporter opened 9 years ago
This is a real blocker for use as we would like to use this in our Tomcat
datasources
Original comment by ps.gr...@gmail.com
on 27 Apr 2010 at 7:12
this is my implements: DataSourceSpy
public class DataSourceSpy implements DataSource{
private DataSource realDataSource;
private boolean enabled = Boolean.parseBoolean(System.getProperty("log4jdbc.enabled","true"));
public DataSourceSpy() {
}
public DataSourceSpy(DataSource realDataSource) {
this.realDataSource = realDataSource;
}
public void setRealDataSource(DataSource realDataSource) {
this.realDataSource = realDataSource;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Connection getConnection() throws SQLException {
if(enabled) {
return new ConnectionSpy(this.realDataSource.getConnection());
}else {
return this.realDataSource.getConnection();
}
}
public Connection getConnection(String username, String password) throws SQLException {
if(enabled) {
return new ConnectionSpy(realDataSource.getConnection(username, password));
}else {
return realDataSource.getConnection(username, password);
}
}
public int getLoginTimeout() throws SQLException {
return realDataSource.getLoginTimeout();
}
public PrintWriter getLogWriter() throws SQLException {
return realDataSource.getLogWriter();
}
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return realDataSource.isWrapperFor(iface);
}
public void setLoginTimeout(int seconds) throws SQLException {
realDataSource.setLoginTimeout(seconds);
}
public void setLogWriter(PrintWriter out) throws SQLException {
realDataSource.setLogWriter(out);
}
public <T> T unwrap(Class<T> iface) throws SQLException {
return realDataSource.unwrap(iface);
}
}
Original comment by bad...@gmail.com
on 13 Aug 2010 at 5:12
this is my DataSourceSpy patch. please intergate
Original comment by bad...@gmail.com
on 14 Aug 2010 at 4:05
Attachments:
badqiu, could you post your jar file containing this patch?
Thanks
Original comment by franklam...@gmail.com
on 24 Nov 2010 at 5:08
My final implemention is :
/**
*
* spring dataSource config:
* <pre>
* <bean id="dataSource" class="net.sf.log4jdbc.DataSourceSpy">
* <property name="realDataSource" ref="realDataSource"/>
* </bean>
* </pre>
*
* log4j.properties
* <pre>
* log4j.logger.jdbc.sqlonly=OFF
* log4j.logger.jdbc.sqltiming=INFO
* log4j.logger.jdbc.audit=OFF
* log4j.logger.jdbc.resultset=OFF
* log4j.logger.jdbc.connection=OFF
* </pre>
*
*
* @author badqiu
*
*/
public class DataSourceSpy implements DataSource{
private DataSource realDataSource;
private RdbmsSpecifics rdbmsSpecifics = null;
public DataSourceSpy() {
}
public DataSourceSpy(DataSource realDataSource) {
setRealDataSource(realDataSource);
}
public void setRealDataSource(DataSource realDataSource) {
this.realDataSource = realDataSource;
}
private RdbmsSpecifics getRdbmsSpecifics() throws SQLException {
if(rdbmsSpecifics == null) {
Connection conn = realDataSource.getConnection();
rdbmsSpecifics = DriverSpy.getRdbmsSpecifics(conn);
conn.close();
}
return rdbmsSpecifics;
}
public Connection getConnection() throws SQLException {
if(SpyLogFactory.getSpyLogDelegator().isJdbcLoggingEnabled()) {
return new ConnectionSpy(this.realDataSource.getConnection(),getRdbmsSpecifics());
}else {
return this.realDataSource.getConnection();
}
}
public Connection getConnection(String username, String password) throws SQLException {
if(SpyLogFactory.getSpyLogDelegator().isJdbcLoggingEnabled()) {
return new ConnectionSpy(realDataSource.getConnection(username, password),getRdbmsSpecifics());
}else {
return realDataSource.getConnection(username, password);
}
}
public int getLoginTimeout() throws SQLException {
return realDataSource.getLoginTimeout();
}
public PrintWriter getLogWriter() throws SQLException {
return realDataSource.getLogWriter();
}
public void setLoginTimeout(int seconds) throws SQLException {
realDataSource.setLoginTimeout(seconds);
}
public void setLogWriter(PrintWriter out) throws SQLException {
realDataSource.setLogWriter(out);
}
}
attachments is my patch
Original comment by bad...@gmail.com
on 24 Nov 2010 at 5:19
Attachments:
Thanks! will try it out.
Original comment by franklam...@gmail.com
on 5 Dec 2010 at 7:32
Thanks, I will try this.
Original comment by ggb...@gmail.com
on 20 Sep 2012 at 1:56
c'mon this is a show stopper. any chance to have it merged to the project?
Original comment by butko...@gmail.com
on 16 Aug 2013 at 1:30
I suppose we could always fork.
Original comment by jpsch...@gmail.com
on 16 Aug 2013 at 1:32
[deleted comment]
There are even two forks with spring datasource support:
https://code.google.com/p/log4jdbc-remix/
https://code.google.com/p/log4jdbc-log4j2/
Original comment by vkopiche...@gmail.com
on 16 Oct 2013 at 8:19
Original issue reported on code.google.com by
jpsch...@gmail.com
on 10 May 2009 at 3:39