Search code examples
hibernatespring-data-jpaspring-datalog4jlog4j2

disabling hibernate: console log in spring @DataJpaTest


I'm getting these logs, the first I know what enables it, the second I have no idea, it's always there. It doesn't seem to go through log4j. How do I disable the log line that begins with Hibernate?

DEBUG - insert into exceptions (created_on, last_modified_on, version, business_division_id, id) values (?, ?, ?, ?, ?) : hibernate.SQL 
Hibernate: insert into exceptions (created_on, last_modified_on, version, business_division_id, id) values (?, ?, ?, ?, ?)

I enabled the first via

logging.level.org.hibernate.SQL=debug

I'm not sure if it matters but I've got H2 auto configured as the database.


Solution

  • The second line seems like the old "log to System.out" Hibernate feature. Since it does not use a logging framework, you can not disable it through Log4j2/Spring Boot configuration.

    You can however disable it by setting hibernate.show_sql to false in your Hibernate properties (cf. Hibernate documentation).

    Since you are using Spring Boot, that option also appears as spring.jpa.show-sql Spring Boot properties (cf. Spring Boot documentation).

    Edit: To disable SQL statement logging you can also set the showSql property on the @DataJpaTest annotation to false.