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

穿精又带淫゛_ 提交于 2019-11-28 06:45:17
fasseg

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

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

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.

I fixed problem with line of code:

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

I am using log4j in my app.

Prashant Pandey

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

a4word

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!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!