The SQL queries show up fine in the terminal output, but when I check the application.log file, I only see regular Spring framework logs. The database queries are missing from the file completely.
How can I make sure the SQL statements get written to the log file along with everything else?
spring.jpa.show-sql doesnt actually use the logging framework - it prints directly to stdout thats why your seeing it in console but not logfile. try removing that and use logging.level.org.hibernate.SQL=DEBUG instead, that should route the queries through proper logging system to your file
hmm thats weird! are you sure the logging.file property is working correctly in your spring boot version? i think newer versions might need logging.file.name instead. also curious - what happens if you set logging.level.org.hibernate.SQL=DEBUG? does that make any difference for getting queries into the file?
The issue stems from how Hibernate handles SQL logging output routing. When using spring.jpa.show-sql=true, Hibernate bypasses the standard logging framework and writes directly to System.out, which explains why queries appear in your console but not in the log file. To resolve this, you need to configure proper logger-based SQL logging instead of relying on the show-sql property. Replace spring.jpa.show-sql=true with logging.level.org.hibernate.SQL=DEBUG and add logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE if you want to see parameter values as well. This approach ensures all SQL statements flow through the same logging infrastructure as your other application logs, making them appear in your specified log file alongside framework messages.