Alex Abdugafarov
Alex Abdugafarov

Reputation: 6422

Turning off logging for Hibernate c3p0

I'm using Hibernate's c3p0 connection pooling and standard Java 1.4 java.util.logging. Upon startup, my app sets up it's logging properties (including formatter and log levels) in static block. Every time I start my app, I see the following:

2011-04-16 17-43-51 [com.mchange.v2.log.MLog] INFO: {MLog.<clinit>) MLog clients using java 1.4+ standard logging.
2011-04-16 17-43-51 [com.mchange.v2.c3p0.C3P0Registry] INFO: {C3P0Registry.banner) Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
2011-04-16 17-43-51 [com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource] INFO: {AbstractPoolBackedDataSource.getPoolManager)
...

I've tried

Logger.getLogger("com.mchange").setLevel(Level.WARNING);
com.mchange.v2.log.MLog.getLogger().setLevel(MLevel.WARNING);
System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");

but only way to prevent it that I found for now is

Logger.getLogger("").setLevel(Level.WARNING);

which affects everything - not a good side effect. Google didn't help. Could anyone help please?

Upvotes: 11

Views: 17692

Answers (7)

D-rk
D-rk

Reputation: 5919

This only happens on older c3p0 version. So it might also be worth checking if you can just update to a newer version.

Upvotes: 0

JRSofty
JRSofty

Reputation: 1256

This is probably really late, but according to the c3p0 project website it is possible to configure the logging inside the mchange-log.properties so that you can capture the information using slf4j or log4j (and thus also with Logback).

The link http://www.mchange.com/projects/c3p0/#configuring_logging provides this information that in your mchange-log.properties file set the property com.mchange.v2.log.MLog to equal com.mchange.v2.log.slf4j.Slf4jMLog then in your logback.xml you can provide a logger like this:

<logger name="com.mchange" level="warn" additivity="false">
    <appender-ref ref="c3p0-log" />
</logger>

Note: you will need to create a logback appender called c3p0-log before you can use this exact piece of code.

Upvotes: 1

Bohdan Levchenko
Bohdan Levchenko

Reputation: 3561

The way I found for achieving this

Create in your classpath a file called mchange-log.properties and put into it properties suggested by Frozen Spider.

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

Thats work fine even when you are not able to set system properties directly.

Upvotes: 17

TomEE
TomEE

Reputation: 598

It appears that c3p0 logging defaults to DEBUG. That can result in a lot of noise.

By adding a line like this to log4j.properties, you are telling the logger not to bother you with c3p0 messages - unless it's something important:

log4j.logger.com.mchange.v2=WARN

Upvotes: 4

Alex Abdugafarov
Alex Abdugafarov

Reputation: 6422

The way I found is to set the system property

System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");

in addition to

System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");

I thought, that absence of any other logging system wil make that optional, but it seems, that I was wrong.

P.S.

Damn those wheel-reinvented custom logging implementations, like the one used by c3p0...

Upvotes: 21

Anantha Sharma
Anantha Sharma

Reputation: 10108

create a file called log4j.properties in your root classpath set the following in there,

# Configure the name of the file for the LOGGER appender
log4j.appender.LOGGER=org.apache.log4j.ConsoleAppender
log4j.appender.LOGGER.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGGER.layout.ConversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
log4j.appender.LOGGER.append=false

# this line logs everything from hibernate package at info level, you can refine this to include only some pachages like log4j.logger.org.hibernate.hql etc.,
log4j.logger.org.hibernate=INFO, LOGGER

log4j.logger.org.jboss.cache=INFO, LOGGER

this is a much better way of implementing the logging because if you set the logging strategy programmatically, then the config sometimes might not take effect at all (like in your case).. if you use the log4j.properties file ,the config is applied at application startup & everything works smoothly.

Upvotes: 0

hooknc
hooknc

Reputation: 5001

Do you not want to see any c3p0 logging?

If so try:

Logger.getLogger("com.mchange.v2.c3p0").setLevel(Level.WARNING);

OR, if you don't even want to see the first line of the log:

Logger.getLogger("com.mchange.v2").setLevel(Level.WARNING);

Upvotes: 3

Related Questions