使用spring记录org.apache.commons.dbcp.BasicDataSource的连接池 [英] logging connection pooling for org.apache.commons.dbcp.BasicDataSource with spring

查看:72
本文介绍了使用spring记录org.apache.commons.dbcp.BasicDataSource的连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用log4j记录org.apache.commons.dbcp.BasicDataSource的连接池

我正在使用spring框架进行dao层注入.

当我在org.apache.commons.dbcp.BasicDataSource中看到代码时,没有使用Logger.因此似乎无法为我记录池化消息.

但是我又看到了这个链接 http://forum.springsource.org/showthread.php?38306 -Connection-Pooling-debug-info .
有人说放 log4j.category.org.apache.dbcp=DEBUG.但是我找不到正确的答案.
所以我的问题是,连接池可以使用log4j for org.apache.commons.dbcp.BasicDataSource记录吗?

解决方案

似乎BasicDataSource仅具有一个PrintWriter,而没有Logger作为成员变量.因此,您必须调用BasicDataSource.setLogWriter(printWriter),其中printWriter只是包装了log4j记录器.

我遇到了这个: http://forum.springsource.org/showthread.php?38306-Connection-Pooling-debug-info.
Some people were saying to put log4j.category.org.apache.dbcp=DEBUG. But I could not find the right answer.
So my question is, can connection pooling log using log4j for org.apache.commons.dbcp.BasicDataSource?

解决方案

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.

这篇关于使用spring记录org.apache.commons.dbcp.BasicDataSource的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆