简体   繁体   English

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

[英]how do I turn off logging in java c3p0 connection pooling lib?

hey all, I'm just getting started with c3p0 for database connection pooling. 嘿所有,我刚刚开始使用c3p0进行数据库连接池。 It's attaching itself to my log4j output currently. 它当前附加到我的log4j输出。 How do I set logging off or at least to SEVERE level only for c3p0? 如何为c3p0设置注销或至少为SEVERE级别? 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.properties文件中工作

log4j.logger.com.mchange.v2.c3p0.impl=INFO

log4j.logger.com.mchange=INFO

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

If you use a log4j.xml file you can simple define a logger for the c3po package: 如果使用log4j.xml文件,则可以简单地为c3po包定义记录器:

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

There are analogous methods for log4j.properties. log4j.properties有类似的方法。 I think it's just: 我认为这只是:

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

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. 这让我觉得C3P0正在记录这些消息。 Actually the message is coming from the mysql connector because I enabled profiling by using a connection string like this: 实际上消息来自mysql连接器,因为我通过使用这样的连接字符串启用了分析:

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

Remove ?profileSQL=true to make it stop logging these messages. 删除?profileSQL=true以使其停止记录这些消息。

I fixed problem with line of code: 我修复了代码行的问题:

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

I am using log4j in my app. 我在我的应用程序中使用log4j。

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). 我正在研究clojure,通过korma和我的生活我无法加载任何属性文件(我是clojure的新手所以我责备自己)。 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! 这基本上是Philippe Carriere上面回答的一个clojure端口,非常感谢你!

You can set log level by adding following lines in log4j.xml Logging at least at Error level is desired. 您可以通过在log4j.xml中添加以下行来设置日志级别。至少需要在错误级别进行日志记录。

< 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 如果你真的想关闭c3P0日志记录集属性com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF

in c3p0-Config.properties 在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); 或者您可以直接在代码中将其设置为System属性System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL",MLevel.OFF);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM