这篇文章主要介绍了Spring boot整合log4j2过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
以前整合过log4j2,但是今天再次整合发现都忘记了,而且也没有记下来
1.pom.xml中
(1)把spring-boot-starter-web包下面的spring-boot-starter-logging排除
org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-logging
说明:
如果不先排除掉自带的log,会出现如下错误
SLF4J: Class path contains multiple SLF4J bindings.
(2)引入spring-boot-starter-log4j2包
org.springframework.boot spring-boot-starter-log4j2
2.添加log4j2配置文件
在srcmainresources添加log4j2-spring.xml
Java程序代码中使用log4j2日志
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Logger logger = LoggerFactory.getLogger(WebMvcConfigurer.class);
logger.error("this is error test");
log.info("this is info test");
启动后会出现log目录,同src在同一级
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



