Can't avoid hibernate logging SQL to console with Spring Boot and Logback

后端 未结 5 1651
失恋的感觉
失恋的感觉 2020-12-15 05:23

My Spring Boot application keeps showing Hibernate queries in the console despite having configured Hibernate\'s specific logging with Logback as follows:

&l         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-15 05:39

    If you set the hibernate.show_sql to true, Hibernate will simply print the SQL statement to the console (not to be confused with logging under org.hibernate.SQL). SqlStatementLogger is responsible for logging the SQL statements and its logStatement looks like:

    public void logStatement(String statement, Formatter formatter) {
        if ( format ) {
            if ( logToStdout || LOG.isDebugEnabled() ) {
                statement = formatter.format( statement );
            }
        }
        LOG.debug( statement );
        if ( logToStdout ) {
            System.out.println( "Hibernate: " + statement );
        }
    }
    

    So, if you do not want to see the queries on the console, just disable the hibernate.show_sql by setting it to false or just removing it altogether. In Spring Boot, just add this to your application.properties:

    spring.jpa.show-sql=false
    

提交回复
热议问题