spring boot sql logging

To enable SQL logging in Spring Boot, you can follow these steps:

  1. Add the necessary dependencies: In your project's pom.xml file (for Maven) or build.gradle file (for Gradle), add the appropriate dependencies for SQL logging. For example, you can add the spring-boot-starter-data-jpa dependency, which includes the necessary components for SQL logging.

  2. Configure the logging level: In your project's application.properties or application.yml file, configure the logging level for SQL statements. You can set the logging level to DEBUG or TRACE for the relevant package or class that handles SQL queries. For example, you can use the following configuration:

logging.level.org.hibernate.SQL=DEBUG

This configuration will enable SQL logging for Hibernate, which is commonly used for database operations in Spring Boot.

  1. Run the application: Start your Spring Boot application, and the SQL statements will be logged based on the configured logging level. You can view the SQL statements in your application's logs, which are typically displayed in the console or written to a log file.

By following these steps, you will be able to enable SQL logging in your Spring Boot application. This can be helpful for debugging and monitoring database interactions during development and testing.