Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

c3p0

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 
like image 808
James Avatar asked Jun 04 '10 17:06

James


People also ask

What is c3p0 connection pool?

c3p0 is a Java library that provides a convenient way for managing database connections. In short, it achieves this by creating a pool of connections. It also effectively handles the cleanup of Statements and ResultSets after use.

What is connection pooling in Java hibernate?

Opening a connection to a database is generally much more expensive than executing an SQL statement. A connection pool is used to minimize the number of connections opened between application and database. It serves as a librarian, checking out connections to application code as needed.


2 Answers

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); 
like image 173
Philippe Carriere Avatar answered Oct 01 '22 03:10

Philippe Carriere


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 
like image 32
fasseg Avatar answered Oct 01 '22 02:10

fasseg