Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't stop Hibernate from writing log to console (log4j.properties is ok)

Tags:

I've already set

<property name="show_sql">false</property> 

and I have disabled all messages in log4j.properties

But Hibernate write to console with all queries & statements.

like image 635
dmitrynikolaev Avatar asked Jan 16 '10 12:01

dmitrynikolaev


People also ask

Does hibernate use log4j?

Hibernate uses Simple Logging Facade for Java (SLF4J) to redirect the logging output to your perfer logging frameworkis (log4j, JCL, JDK logging, lofback…).

Which hibernate logging dependency is required?

The jboss-logging jar is a required dependency of Hibernate and therefore will always need to be on the classpath.

What logger does hibernate use?

Logging. Hibernate utilizes Simple Logging Facade for Java (SLF4J) in order to log various system events.


2 Answers

Setting the hibernate.show_sql to true tells hibernate to Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug.

So even if you set this property to false, make sure that you don't have the following category defined (or configured to use a console appender):

log4j.logger.org.hibernate.SQL=DEBUG 

Also, make sure that you don't set the hibernate.show_sql programmatically to true when instancing your Configuration object. Hunt something like this:

Configuration cfg = new Configuration().configure().     .setProperty("hibernate.show_sql", "true"); 

Note that the setProperty(String propertyName, String value) takes as first parameter the full name of a configuration property i.e. hibernate.show_sql, not just show_sql.

like image 75
Pascal Thivent Avatar answered Oct 13 '22 22:10

Pascal Thivent


HI there, i figured out you can solve this also with this 2 lines in your log4j.properties file.

log4j.logger.org.hibernate = WARN log4j.logger.org.hibernate = ERROR 
like image 39
MadMad666 Avatar answered Oct 14 '22 00:10

MadMad666