1、log4j2依赖
pom.xml
<!-- log4j2 日志模块 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.8.2</version> </dependency>
2、在resources目录下创建 log4j2.xml文件
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO" monitorInterval="1800"> <appenders> <Console name="consolePrint" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" /> </Console> </appenders> <loggers> <!-- 将业务dao接口填写进去,并用控制台输出即可 --> <logger name="cn.zgmh.zxks.mapper.dao" level="DEBUG" additivity="false"> <appender-ref ref="consolePrint"/> </logger> <root level="info"> <appender-ref ref="consolePrint" /> </root> </loggers> </Configuration>
3、在web.xml中进行配置
<!-- log4j2 日志 --> <context-param> <param-name>log4jConfiguration</param-name>
<param-value>classpath:log4j2.xml</param-value> </context-param> <listener> <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class> </listener>
4、在mybatis配置文件中 配置
<settings> <!-- 开启驼峰命名 --> <setting name="mapUnderscoreToCamelCase" value="true" /> <!-- log4j2日志 --> <setting name="logImpl" value="LOG4J2" /> </settings>
5、已经配置ok了。可以看下效果了