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

8

39

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
Wimbush answered 4/6, 2010 at 17:13 Comment(0)
N
24

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
Nozzle answered 4/6, 2010 at 17:25 Comment(5)
I'm currently using a log4j.properties file, any idea how to do it in there?Wimbush
added a log4j.properties logger exampleNozzle
thanks! I had to tweak it a little but the log4j.properties file worked :)Wimbush
@Wimbush how would this looks like in log4j2 properties file?Verena
How to do this in log4j2.properties?Cubical
R
41

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);
Remaremain answered 16/5, 2011 at 15:54 Comment(1)
import java.util.Properties;Mangosteen
N
24

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
Nozzle answered 4/6, 2010 at 17:25 Comment(5)
I'm currently using a log4j.properties file, any idea how to do it in there?Wimbush
added a log4j.properties logger exampleNozzle
thanks! I had to tweak it a little but the log4j.properties file worked :)Wimbush
@Wimbush how would this looks like in log4j2 properties file?Verena
How to do this in log4j2.properties?Cubical
E
4

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.

Evilminded answered 12/2, 2013 at 19:15 Comment(0)
M
2

I fixed problem with line of code:

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

I am using log4j in my app.

Macrocosm answered 21/2, 2011 at 8:48 Comment(0)
V
1

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

Vu answered 14/1, 2011 at 15:25 Comment(1)
Adding one more additional line in properties file worked for me , com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLogSavoie
B
1

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!

Bensky answered 28/1, 2015 at 18:17 Comment(2)
Using Korma I needed to use this code before requiring its namespaces.Appellee
Yes, sorry forgot to mention that. If Korma is loaded, then the defaults so the lines above won't overwrite what is already set.Bensky
S
0

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

logging.level.com.mchange.v2.c3p0=off
Staciestack answered 15/5, 2023 at 7:14 Comment(0)
S
0

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.

Swee answered 9/6 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.