Home >Java >javaTutorial >Why Aren't My Spring Boot SQL Statements Being Logged to a File?

Why Aren't My Spring Boot SQL Statements Being Logged to a File?

Linda Hamilton
Linda HamiltonOriginal
2024-11-29 00:16:11698browse

Why Aren't My Spring Boot SQL Statements Being Logged to a File?

Logging SQL Statements in Spring Boot

Despite enabling SQL statement display and formatting in application.properties, SQL statements are not being logged to the designated file.

Issue

In your configuration, you've specified:

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

While these settings allow for console logging of SQL statements, they do not redirect them to a log file.

Solution

To log SQL statements to a file, add the following properties to your application.properties:

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

Explanation

  • logging.level.org.hibernate.SQL=DEBUG: Sets the log level for Hibernate SQL statements to DEBUG.
  • logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE: Sets the log level for Hibernate SQL parameter binding to TRACE.

The above is the detailed content of Why Aren't My Spring Boot SQL Statements Being Logged to a File?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn