-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Disable hibernate logging
PostPosted: Wed Jan 07, 2009 2:23 pm 
Newbie

Joined: Tue Aug 14, 2007 10:31 am
Posts: 4
Hey guys,

For our software we'd like to suppress the log messages outputted by hibernate(on startup for example). We don't use a hibernate.cfg.xml file, we configure our session factory using setProperty calls in java instead. Does anyone know how to do this?

I have read through a few posts which suggest to modify your log4j.properties file. I have tried setting the log level in a properties file and placing it in the classpath and in the source folder and have had no luck.

Thanks in advance for the info!
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 11:21 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi,

can you post your configuration for log4j?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 9:00 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
If you're using log4j, you have several options for disabling logging.


1. To disable all hibernate logging, change this line in your log4j.properties file:
log4j.logger.net.sf.hibernate=info

to: =warn or =error or =fatal.


2. To disable most of the configuration logging, add this to your log4j.properties file:
### log configuration
log4j.logger.net.sf.hibernate.cfg=warn



3. Or you could temporarily disable hibernate logging with:
org.apache.log4j.Logger.getLogger("net.sf.hibernate").setLevel(org.apache.log4j.Level.WARN);

and then reset logging after startup with:
org.apache.log4j.Logger.getLogger("net.sf.hibernate").setLevel(org.apache.log4j.Level.INFO);

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 12:40 pm 
Newbie

Joined: Tue Aug 14, 2007 10:31 am
Posts: 4
Thanks for the help, unfortunately we ran out of time to work on this issue since we needed it before our demo. Your help is much appreciated.

-Brian

Madan_Prabhu wrote:
If you're using log4j, you have several options for disabling logging.


1. To disable all hibernate logging, change this line in your log4j.properties file:
log4j.logger.net.sf.hibernate=info

to: =warn or =error or =fatal.


2. To disable most of the configuration logging, add this to your log4j.properties file:
### log configuration
log4j.logger.net.sf.hibernate.cfg=warn



3. Or you could temporarily disable hibernate logging with:
org.apache.log4j.Logger.getLogger("net.sf.hibernate").setLevel(org.apache.log4j.Level.WARN);

and then reset logging after startup with:
org.apache.log4j.Logger.getLogger("net.sf.hibernate").setLevel(org.apache.log4j.Level.INFO);


Top
 Profile  
 
 Post subject: Re: Disable hibernate logging
PostPosted: Tue Sep 21, 2010 2:50 pm 
Newbie

Joined: Wed Sep 15, 2010 10:53 am
Posts: 7
Hi,

i did the same , but its not working for me. Can you pls help me where i am missing..

<logger name="org.Hibernate">
<level value="fatal" />
<appender-ref ref="ASYNC_APPENDER" />
</logger>
<logger name="org.Hibernate.SQL">
<level value="fatal" />
<appender-ref ref="ASYNC_APPENDER" />
</logger>

and having jars like log4j,slfapi,slglog4j, commons-loggin

thanks
jayaram


Top
 Profile  
 
 Post subject: Re: Disable hibernate logging
PostPosted: Wed Sep 22, 2010 11:24 am 
Newbie

Joined: Wed Sep 15, 2010 10:53 am
Posts: 7
Guys,

please help me as i am stucking here. I have log4j.xml and jars

<LOCAL>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<appender name="ASYNC_APPENDER" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="citimortgage" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d] %-5p %c - %m%n" />
</layout>
</appender>
<logger name="citimortgage" additivity="true">
<level value="debug" />
<appender-ref ref="ASYNC_APPENDER" />
</logger>
<logger name="org.apache" additivity="true">
<level value="error"></level>
<appender-ref ref="ASYNC_APPENDER"></appender-ref>
</logger>
<logger name="com.citigroup.rel.common.webservice" additivity="false">
<level value="debug" />
<appender-ref ref="ASYNC" />
</logger>
<!-- Coding change for R35937 Local-->
<logger name = "org.apache.velocity" additivity = "false" >
<level value = "debug" />
<appender-ref ref = "ASYNC" />
</logger >
<!-- End of Coding change for R35937 Local-->
<logger name="org.hibernate">
<level value="fatal" />
<appender-ref ref="ASYNC_APPENDER" />
</logger>
<logger name="org.hibernate.SQL">
<level value="fatal" />
<appender-ref ref="ASYNC_APPENDER" />
</logger>
<root>
<priority value="debug"/>
<appender-ref ref="ASYNC_APPENDER"/>
</root>
</log4j:configuration>
</LOCAL>

Still its not working, please help me where i am missing...

thanks
jayaram


Top
 Profile  
 
 Post subject: Re: Disable hibernate logging
PostPosted: Wed Sep 22, 2010 2:08 pm 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
The logger your defined will inherit from root by default in log4j. So what ever you defined there, you do not have to redefine again unless you want to overwrite it. And if you overwrite it, you only have to specify log level, not the appender reference, other wise you will have double logging output. With the exception of setting additivity="false", in this case you are turning the "inheritance" off.

Try to set your "root" logger to ERROR, then lower your other custom loggers level if needed basis. So in this way, just omitting the hibernate logger will in effect NOT output anything higher than ERROR msg. If you insist on NOT wanting ERROR msg at all, then set your root to OFF level (not recommended).

Example:
Code:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<appender name="ASYNC_APPENDER" class="org.apache.log4j.AsyncAppender">
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="citimortgage" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d] %-5p %c - %m%n" />
</layout>
</appender>
<logger name="citimortgage" additivity="true">
<level value="debug" />
</logger>
<logger name="com.citigroup.rel.common.webservice" additivity="false">
<level value="debug" />
</logger>
<!-- Coding change for R35937 Local-->
<logger name = "org.apache.velocity" additivity = "false" >
<level value = "debug" />
<appender-ref ref = "ASYNC" />
</logger >

<!-- Enable this if you want to see hibernate logging
<logger name="org.hibernate">
<level value="INFO" />
</logger>
-->
<root>
<priority value="ERROR"/>
<appender-ref ref="ASYNC_APPENDER"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>


Also, these are explained very clearly in the log4j manual documentation. READ IT!

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


Top
 Profile  
 
 Post subject: Re: Disable hibernate logging
PostPosted: Thu May 10, 2012 1:46 pm 
Newbie

Joined: Thu May 10, 2012 11:58 am
Posts: 1
I finally figured out, it's because the Hibernate is using slf4j log facade now, to bridge to log4j, you need to put log4j and slf4j-log4j12 jars to your lib and then the log4j properties will take control Hibernate logs.

My pom.xml setting looks as below:

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.