1. 引入Log4J的Maven依赖:
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
2. 修改MyBatis的配置文件,设置使用Log4J日志输出方式:
<setting name="logImpl" value="STDOUT_LOGGING" />
如果是Spring Boot项目,则指定:
3. 在资源路径下新建log4j.properties:
log4j.rootLogger=DEBUG, Console #Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO log4j.logger.org.apache=INFO log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG
.
时间: 2024-11-04 14:23:44