Turning off logging for Hibernate c3p0
Asked Answered
B

7

11

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?

Bauxite answered 16/4, 2011 at 12:52 Comment(0)
B
21

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...

Bauxite answered 18/4, 2011 at 4:55 Comment(1)
Very useful to actually redirect log to console [in my case tomcat logs].Chantel
O
17

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.

Ogdan answered 25/10, 2014 at 15:52 Comment(2)
Added this to my log4j.properties. And additionally, com.mchange.v2.log.MLog.getLogger().setLevel(MLevel.SEVERE);Porism
can we add this in log4j2.xml ?Untouched
I
4

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
Ixion answered 2/2, 2013 at 22:58 Comment(0)
M
3

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);
Manuelmanuela answered 16/4, 2011 at 15:41 Comment(2)
At what point are you programmatically setting the above log levels? Perhaps, the logging you're attempting to get rid of logs prior to the code above executing. Can you verify to see if the logging you want to remove happens prior to the code above executing?Manuelmanuela
No, they happens after that. It can be verified by using Logger.getLogger("").setLevel(Level.WARNING); or the method that I describe in my own reply. The point is to get rid of annoying (at least for me) pile of configuration files - Hibernate requires enough of them already. Besides, I still don't see any substantial advantages of log4j or Logback over jdk1.4 logging package.Bauxite
U
1

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.

Ur answered 19/12, 2017 at 13:42 Comment(0)
C
0

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.

Cutpurse answered 17/4, 2011 at 5:3 Comment(0)
A
0

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

Argentinaargentine answered 3/2, 2020 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.