Java – you cannot avoid using spring boot and logback to log SQL into the console

Solution

If hibernate show_ If SQL is set to true, hibernate will simply print the SQL statement to the console (do not confuse it with the log record under org.hibernate.sql) Sqlstatementlogger is responsible for recording SQL statements. Its logstatement is as follows:

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 );
    }
}

Therefore, if you don't want to view the query on the console, just put hibernate show_ SQL can be disabled by setting it to false or simply deleting it In spring boot, just add it to your application properties:

spring.jpa.show-sql=false
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>