如何关闭 java c3p0 连接池库中的日志记录?
大家好,我刚刚开始使用 c3p0 进行数据库连接池。它当前正在将自身附加到我的 log4j 输出。如何仅针对 c3p0 设置注销或至少设置为 SEVERE 级别?我尝试调整属性文件,但不确定它是否被正确拾取。
关于如何最好地关闭它有什么想法吗?
谢谢
更新: 这似乎在 log4j.properties 文件中起作用
log4j.logger.com.mchange.v2.c3p0.impl=INFO
log4j.logger.com.mchange=INFO
hey all, I'm just getting started with c3p0 for database connection pooling. It's attaching itself to my log4j output currently. How do I set logging off or at least to SEVERE level only for c3p0? I tried tweaking the properties file but not sure it's being picked up properly.
any ideas on how best to turn it off?
thanks
UPDATE:
this seems to work in the log4j.properties file
log4j.logger.com.mchange.v2.c3p0.impl=INFO
log4j.logger.com.mchange=INFO
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
对于那些不使用配置文件的人,只需在加载连接池之前在代码中添加以下内容即可。
For those who are NOT using a configuration file, just to add the following in the code, before loading the connection pool.
如果您使用 log4j.xml 文件,您可以简单地为 c3po 包定义一个记录器:
log4j.properties 有类似的方法。我认为这只是:
If you use a log4j.xml file you can simple define a logger for the c3po package:
There are analogous methods for log4j.properties. I think it's just:
我收到如下消息:
这让我认为 C3P0 正在记录这些消息。实际上,该消息来自 mysql 连接器,因为我通过使用如下连接字符串启用了分析:
删除
?profileSQL=true
以使其停止记录这些消息。I was getting messages like the following:
This made me think that C3P0 was logging these messages. Actually the message is coming from the mysql connector because I enabled profiling by using a connection string like this:
Remove
?profileSQL=true
to make it stop logging these messages.我解决了代码行的问题:
我在我的应用程序中使用 log4j。
I fixed problem with line of code:
I am using log4j in my app.
您可以通过在 log4j.xml 中添加以下行来设置日志级别
需要至少在错误级别进行日志记录。
如果您确实想关闭
c3p0-Config.properties 中的
c3P0 日志记录集属性
com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF
,或者您可以直接在代码中将其设置为系统属性<代码>System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL",MLevel.OFF);You can set log level by adding following lines in log4j.xml
Logging at least at Error level is desired.
If you really want to turn off c3P0 logging set property
com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF
in c3p0-Config.properties
or you can directly set this in code as an System property
System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL",MLevel.OFF);
我正在通过 korma 开发 clojure,并且在我的一生中我无法加载任何属性文件(我是 clojure 的新手,所以我责怪自己)。如果您也有类似的情况,以下内容可能会对您有所帮助。
这基本上是 Philippe Carriere 上面答案的 Clojure 移植,非常感谢!
I am working on clojure, through korma and for the life of my I could not get any properties files to load (I am new to clojure so I blame myself). If you are in a similar boat, the following might help you out.
The is basically a clojure port of Philippe Carriere's answer above, thank you so much!
如果您使用 Spring,您可以通过在 application.properties 中配置来禁用 c3p0 日志记录:
If you are using Spring, you can disable c3p0 logging by configuring it in application.properties:
以下解决方案确实有效:
但其他配置解决方案都不适合我。最后,我通过在类路径(src/test/resources)中创建包含以下内容的文件 mchange-log.properties 成功抑制了它:
我在以下位置找到了解决方案:
http://springoftech.blogspot.com/2012/10/ using-c3p0-with-logback.html
希望有人觉得它有用。
The following solution did work:
But none of other configuration solution work for me. At the end i successfully suppressed it by creating file mchange-log.properties in my classpath (src/test/resources) with the following content:
I found solution at:
http://springoftech.blogspot.com/2012/10/using-c3p0-with-logback.html
Hope somebody find it useful.