MyBatis3-configure to output logs using log4j, mybatis3-log4j
Configuration steps:
1. Introduce POM Dependencies
<!-- log4j --> <!-- https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
2. Add log4j. properties to resources. The content is as follows:
log4j.rootLogger=DEBUG,Consolelog4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%nlog4j.logger.org.apache=INFO#ex:http://www.cnblogs.com/zhaozihan/p/6371133.html
Of course, there are many more detailed configurations on the Internet. You can search for them. Here we use the configuration of http://www.cnblogs.com/zhaozihan/p/6371133.html.
3. Add the following Configuration in Configuration. xml:
<properties> <property name="dialect" value="mysql" /> </properties> <settings> <setting name="logImpl" value="LOG4J" /> </settings>
After configuration, the running effect is as follows:
Key configurations of log output:<Setting name = "logImpl" value = "LOG4J"/>Only after this sentence is configured can the SQL statement be output normally.
If other log components need to be configured, you can use this option to specify the type of log components. Reference: http://www.mybatis.org/mybatis-3/zh/configuration.html#settings