• Mybatis provides logging functionality by using a built-in log factory
  • Method: In the Mybatis configuration file, add Settings and add setting. The configuration is as follows:
<configuration>
  <settings>.<setting name="logImpl" value="LOG4J"/>.</settings>
</configuration>
Copy the code

The possible values are: SLF4J, LOG4J, LOG4J2, JDK_LOGGING, COMMONS_LOGGING, STDOUT_LOGGING, NO_LOGGING, or is the realization of the org. Apache. The ibatis. Logging. The Log interface, The fully qualified name of the class whose constructor takes a string.

You can also call the following any method to choose the logging implementation: org. Apache. Ibatis. Logging. LogFactory. UseSlf4jLogging (); org.apache.ibatis.logging.LogFactory.useLog4JLogging(); org.apache.ibatis.logging.LogFactory.useJdkLogging(); org.apache.ibatis.logging.LogFactory.useCommonsLogging(); org.apache.ibatis.logging.LogFactory.useStdOutLogging();

  • With STDOUT_LOGGING, it can be configured directly
  • Using Log4J, the steps are as follows:
  1. Add the Log4J JAR package
<! -- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
    <scope>compile</scope>
</dependency>
Copy the code
  1. Add in Resourceslog4j.propertiesAdd the following to the configuration file:
# Global log configuration
log4j.rootLogger=DEBUG, stdout
Console output
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
Copy the code
  1. Modify Mybatis configuration file
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
Copy the code
  1. At this point, it is ready to use