How to Prevent Hibernate SQL Logging to Console in Spring Boot with Logback

Question

How can I stop Hibernate from logging SQL statements to the console in a Spring Boot application using Logback?

# Example Logback configuration to suppress Hibernate SQL logging
<configuration>
  <logger name="org.hibernate.SQL" level="WARN"/>
  <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="WARN"/>
</configuration>

Answer

When working with a Spring Boot application that uses Hibernate as the ORM (Object-Relational Mapping) tool, you might find that SQL statements are logged to the console by default. While this can be useful for debugging purposes, it can also clutter your logs and affect performance. In this guide, we'll explore how to suppress these SQL logging statements using Logback.

# logback-spring.xml configuration to disable Hibernate SQL logging:
<configuration>
  <logger name="org.hibernate.SQL" level="WARN"/>
  <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="WARN"/>
</configuration>

Causes

  • Hibernate is configured to log SQL statements at the INFO or DEBUG level.
  • Logback retains default logging settings which capture these log levels.

Solutions

  • Modify the Logback configuration to adjust the logging level for the Hibernate SQL logger.
  • Set specific Hibernate properties to reduce or eliminate SQL logging.

Common Mistakes

Mistake: Forgetting to include the logback-spring.xml configuration file in the resources folder.

Solution: Ensure that the logback-spring.xml file is located in the src/main/resources directory.

Mistake: Not restarting the Spring Boot application after making changes to the logging configuration.

Solution: Always restart your application to apply changes in the logging configuration.

Helpers

  • Spring Boot
  • Hibernate SQL logging
  • Logback configuration
  • disable Hibernate logging
  • suppress SQL statements
  • Spring Boot logging settings

Related Questions

⦿Understanding Why @PostConstruct Annotations May Not Be Invoked in Java Applications

Explore common reasons PostConstruct is not called in Java applications and learn solutions to ensure successful method invocation.

⦿How to Resolve 404 Errors During Logout in Spring Security

Learn how to troubleshoot and fix 404 errors that occur during logout in Spring Security applications. Stepbystep guide provided.

⦿How Do HashSet, TreeSet, and LinkedHashSet Handle Duplicate Values?

Explore how HashSet TreeSet and LinkedHashSet in Java treat duplicate values including features performance and code examples.

⦿Why Does My Java ProcessBuilder Result in a Hanging Process?

Learn why your Java ProcessBuilder might be causing a hanging process and find solutions to fix it efficiently.

⦿How to Combine Multiple Collections into a Single Collection in Java 8

Learn how to efficiently merge multiple collections into one using Java 8s Stream API with practical examples and best practices.

⦿How to Use Lombok with Maven for Java Development

Learn how to integrate Lombok with Maven for efficient Java development. Stepbystep guide with code snippets and troubleshooting tips.

⦿How to Group List Elements into Sublists Using Guava

Learn how to efficiently group elements of a list into sublists using Guava in Java with examples and best practices.

⦿How to Merge Multiple PNG Files into a Single PNG Image

Learn how to combine multiple PNG images into one versatile PNG file with detailed steps and code examples.

⦿How to Automatically Generate Javadoc Comments in Eclipse IDE

Learn how to autogenerate Javadoc comments in Eclipse IDE to enhance your Java code documentation efficiently.

⦿How Does JPA Default Column Name Mapping Work for @ManyToOne Relationships?

Learn how JPA handles default column name mapping for ManyToOne relationships and explore common configurations and issues.

© Copyright 2025 - CodingTechRoom.com