How can I log SQL statements in Spring Boot?
To log SQL statements in Spring Boot, you can configure the logging level of the org.hibernate.SQL
logger to DEBUG
or TRACE
.
Here's an example of how you can do this in a application.properties
file:
logging.level.org.hibernate.SQL=DEBUG
This will log all SQL statements executed by Hibernate at the DEBUG
level.
Alternatively, you can use the show-sql
property of the spring.jpa.properties
configuration to enable logging of SQL statements.
spring.jpa.show-sql=true
This will log all SQL statements executed by Hibernate at the INFO
level.
Note that these configurations will only log SQL statements executed by Hibernate. If you want to log all SQL statements executed by the database, you will need to configure the database driver to log the statements.