HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaspringCritical

How can I log SQL statements in Spring Boot?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howsqllogspringstatementscanboot

Problem

I want to log SQL statements to a file.

I have the following properties in application.properties:
spring.datasource.url=...
spring.datasource.username=user
spring.datasource.password=1234
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver

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

security.ignored=true
security.basic.enabled=false

logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO
logging.file=c:/temp/my-log/app.log


When I run my application,
cmd> mvn spring-boot:run


I can see SQL statements in the console, but they don't appear in app.log. The file contains only basic logs from Spring.

What should I do to see SQL statements in the log file?

Solution

Try using this in your properties file:

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

Code Snippets

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

Context

Stack Overflow Q#30118683, score: 681

Revisions (0)

No revisions yet.