如何关闭 java c3p0 连接池库中的日志记录?

发布于 2024-09-04 10:35:38 字数 289 浏览 6 评论 0原文

大家好,我刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

苍白女子 2024-09-11 10:35:38

对于那些不使用配置文件的人,只需在加载连接池之前在代码中添加以下内容即可。

Properties p = new Properties(System.getProperties());
p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any other level
System.setProperties(p);

For those who are NOT using a configuration file, just to add the following in the code, before loading the connection pool.

Properties p = new Properties(System.getProperties());
p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any other level
System.setProperties(p);
秋叶绚丽 2024-09-11 10:35:38

如果您使用 log4j.xml 文件,您可以简单地为 c3po 包定义一个记录器:

<logger name="com.mchange.v2.c3p0">
    <level value="SEVERE"/>
</logger>

log4j.properties 有类似的方法。我认为这只是:

log4j.logger.com.mchange.v2.c3p0=SEVERE

If you use a log4j.xml file you can simple define a logger for the c3po package:

<logger name="com.mchange.v2.c3p0">
    <level value="SEVERE"/>
</logger>

There are analogous methods for log4j.properties. I think it's just:

log4j.logger.com.mchange.v2.c3p0=SEVERE
无语# 2024-09-11 10:35:38

我收到如下消息:

Tue Feb 12 13:42:01 EST 2013 INFO: Profiler Event: [FETCH]  at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) duration: 0 ms, connection-id: 67, statement-id: 23, resultset-id: 27

这让我认为 C3P0 正在记录这些消息。实际上,该消息来自 mysql 连接器,因为我通过使用如下连接字符串启用了分析:

jdbc:mysql://localhost/database?profileSQL=true

删除 ?profileSQL=true 以使其停止记录这些消息。

I was getting messages like the following:

Tue Feb 12 13:42:01 EST 2013 INFO: Profiler Event: [FETCH]  at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) duration: 0 ms, connection-id: 67, statement-id: 23, resultset-id: 27

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:

jdbc:mysql://localhost/database?profileSQL=true

Remove ?profileSQL=true to make it stop logging these messages.

っ〆星空下的拥抱 2024-09-11 10:35:38

我解决了代码行的问题:

com.mchange.v2.log.MLog.getLogger().setLevel(MLevel.INFO);

我在我的应用程序中使用 log4j。

I fixed problem with line of code:

com.mchange.v2.log.MLog.getLogger().setLevel(MLevel.INFO);

I am using log4j in my app.

囚我心虐我身 2024-09-11 10:35:38

您可以通过在 log4j.xml 中添加以下行来设置日志级别
需要至少在错误级别进行日志记录。

< category name="com.mchange" additivity="false"> 
        < priority value="ERROR"/>
        < appender-ref ref="ASYNC"/>
     </ category>

如果您确实想关闭

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.

< category name="com.mchange" additivity="false"> 
        < priority value="ERROR"/>
        < appender-ref ref="ASYNC"/>
     </ category>

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);

混吃等死 2024-09-11 10:35:38

我正在通过 korma 开发 clojure,并且在我的一生中我无法加载任何属性文件(我是 clojure 的新手,所以我责怪自己)。如果您也有类似的情况,以下内容可能会对您有所帮助。

(System/setProperties 
  (doto (java.util.Properties. (System/getProperties))
    (.put "com.mchange.v2.log.MLog" "com.mchange.v2.log.FallbackMLog")
    (.put "com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL" "OFF")))

这基本上是 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.

(System/setProperties 
  (doto (java.util.Properties. (System/getProperties))
    (.put "com.mchange.v2.log.MLog" "com.mchange.v2.log.FallbackMLog")
    (.put "com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL" "OFF")))

The is basically a clojure port of Philippe Carriere's answer above, thank you so much!

峩卟喜欢 2024-09-11 10:35:38

如果您使用 Spring,您可以通过在 application.properties 中配置来禁用 c3p0 日志记录:

logging.level.com.mchange.v2.c3p0=off

If you are using Spring, you can disable c3p0 logging by configuring it in application.properties:

logging.level.com.mchange.v2.c3p0=off
无法言说的痛 2024-09-11 10:35:38

以下解决方案确实有效:

Properties p = new Properties(System.getProperties());
p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any other level
System.setProperties(p);

但其他配置解决方案都不适合我。最后,我通过在类路径(src/test/resources)中创建包含以下内容的文件 mchange-log.properties 成功抑制了它:

com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog
com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF

我在以下位置找到了解决方案:
http://springoftech.blogspot.com/2012/10/ using-c3p0-with-logback.html

希望有人觉得它有用。

The following solution did work:

Properties p = new Properties(System.getProperties());
p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any other level
System.setProperties(p);

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:

com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog
com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF

I found solution at:
http://springoftech.blogspot.com/2012/10/using-c3p0-with-logback.html

Hope somebody find it useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文