logging connection pooling for org.apache.commons.dbcp.BasicDataSource with spring

前端 未结 2 1218
长发绾君心
长发绾君心 2021-02-13 05:37

I am trying to log connection pooling for org.apache.commons.dbcp.BasicDataSource using log4j

I am using spring framework for dao layer injection.

W

2条回答
  •  别那么骄傲
    2021-02-13 06:11

    It seems that BasicDataSource only has a PrintWriter, not a Logger as a member variable. So you'd have to call BasicDataSource.setLogWriter(printWriter) where the printWriter is simply wrapping your log4j logger.

    I came across this: http://www.opensource.apple.com/source/JBoss/JBoss-737/jboss-all/common/src/main/org/jboss/logging/util/LoggerWriter.java

    which seems to do exactly that. I don't know of a tool in Apache Commons that does something similar, but the class in the link above seems like it would accomplish what you are looking for.

提交回复
热议问题