一、在pom.xml文件中导入log4j2的依赖
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.4</version>
</dependency>
二、在resources(类路径)下创建log4j2.xml文件,写入如下内容
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</appenders>
<loggers>
<root level="info">
<appender-ref ref="Console"/>
</root>
<logger name="com.cwx.mybatisDemo.dao" level="debug" additivity="false">
<appender-ref ref="Console"/>
</logger>
</loggers>
</configuration>
三、确保log4j2生效,在mybatis.xml文件中设置setting
<settings>
<setting name="logImpl" value="LOG4J2"/>
</settings>
四、测试
|