Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Hibernate log messages in a Spring application

I have configured my pom.xml to include slf4j and bindings to log4j and exclude commons-logging as explained here and disabled Hibernate's own logging as explained here.

I can suppress Spring's own messages, but Hibernate messages still come out despite my log4j.properties settings below.

log4j.debug=false
log4j.rootCategory=WARN, stdout
log4j.category.org.hibernate=ERROR, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %t %c - %m%n
log4j.category.org.springframework = ERROR
log4j.category.org.hibernate = ERROR

Here is my pom.xml file:

What could be the issue? I am seeing all the sql messages hibernate generates.

like image 318
ustun Avatar asked Oct 28 '11 12:10

ustun


People also ask

How do I enable Hibernate logs in spring?

Enabling Hibernate logs is usually as simple as setting org. hibernate logging level to TRACE or ALL using your logging framework configuration of choice.

Does spring boot have Hibernate?

As their names suggest, these are the starting dependencies in Spring Boot. This dependency includes JPA API, JPA Implementation, JDBC, and the other necessary libraries. Since the default JPA implementation is Hibernate, this dependency is actually enough to bring it in as well.

What is logging in Hibernate?

Hibernate utilizes Simple Logging Facade for Java (SLF4J) in order to log various system events. SLF4J can direct your logging output to several logging frameworks (NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL or logback) depending on your chosen binding.


2 Answers

If anyone looks up this question while browsing for answers:

IF you are using spring-boot-starter-data-jpa, set spring.jpa.show_sql = false in your application.properties file.

like image 177
Jørgen Skår Fischer Avatar answered Sep 20 '22 15:09

Jørgen Skår Fischer


If you're using it, you might need to set <property name="show_sql">false</property> in your hibernate configuration file.

like image 33
Xavi López Avatar answered Sep 20 '22 15:09

Xavi López