SoFunction
Updated on 2025-04-26

How to turn off SQL log output in MyBatis-Plus

Turn off SQL log output in MyBatis-Plus

When developing Java applications using MyBatis-Plus, as the complexity of the project increases, the output of SQL logs may cause the log files to become huge, affecting the performance and maintainability of the system. Therefore, it is very important to properly configure the SQL log level to turn off unnecessary output. This article will explain how to turn off SQL log output of MyBatis-Plus in a Spring Boot project.

1. What is MyBatis-Plus?

MyBatis-Plus is an enhancement tool for MyBatis, aiming to simplify the use of MyBatis and improve development efficiency. It provides a wealth of features such as code generation, conditional constructors, and automatic paging.

2. Necessity to turn off SQL log output

In a development environment, SQL logs can help developers debug and understand data flow. However, in production environments, continuous SQL log output can take up disk space and can lead to system performance degradation. To deal with this problem, we can turn off the SQL log output of MyBatis-Plus by configuring it.

3. Method 1: Modify or file

In your Spring Boot project, findor the configuration file corresponding to the operating environment (e.g.) and add the following configuration items:

mybatis-plus:
  configuration:
    log-impl: 

After this configuration, MyBatis-Plus will no longer output SQL logs.

4. Method 2: Configure log level

If you want to retain the logging function but lower the log level, you can add the following content to the configuration file to output only ERROR and above logs:

logging:
  level:
    : ERROR
    : ERROR

In this way, you can effectively reduce log output while retaining critical error information.

5. Method 3: Use Java code to configure

Not only can we close SQL logs through configuration files, we can also configure them through Java code. In the configuration class of MyBatis-Plus, add the following content:

import ;
import ;
import ;
import ;
import ;
@Configuration
@MapperScan("")
public class MyBatisPlusConfig {
    @Bean
    @Primary
    public MybatisPlusProperties mybatisPlusProperties() {
        MybatisPlusProperties properties = new MybatisPlusProperties();
        ().setSqlParser(null); // Close SQL logs        return properties;
    }
}

In this configuration, we turn off the output of the SQL log through Java code.

6. Testing and Verification

After completing the above configuration, restart your Spring Boot application and test it. Confirm that SQL logs are no longer output in the production environment. If necessary, please adjust the log configuration according to the actual situation.

Summarize

Through the above method, we can effectively turn off the SQL log output of MyBatis-Plus to improve the performance and maintainability of the program. In actual development, log levels can be flexibly adjusted according to different environments to achieve the best development experience and production performance.

I hope this article can help you and have a deeper understanding of MyBatis-Plus log management! If you have any questions, please leave a message in the comment area and we will discuss it together.

This is the article about how to turn off SQL log output in MyBatis-Plus. For more related content related to MyBatis-Plus, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!