第三篇 SpringBoot整合log4j2详解


源代码:https://pan.baidu.com/s/1d1Lwv1gIvVNltIKVWeEseA
提取码:wff0

SpringBoot整合Log4j2步骤:
1、删除spring-boot-starter-parent默认使用spring-boot-starter-logging依赖
2、在pom.xml中增加spring-boot-starter-log4j2依赖
3、创建log4j2.xml文件即可
4、执行,指定目录会生成相应的log文件

1:删除spring-boot-starter-logging见下图,打开pom.xml文件最终定位到spring-boot-dependencies文件,在此文件中将Logging依赖注释掉即可

将spring-boot-starter-logging注释后别忙着执行或debug会报错:SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
将spring-boot-starter-log4j2依赖添加到pom.xml后就没这个问题了
注意:下面version版本,2.2.7.RELEASE会失效,可能是版本不匹配,所以使用下面的版本同截图
org.springframework.boot
http://logging.apache.org/log4j/2.x/manual/appenders.html

源代码:https://pan.baidu.com/s/1d1Lwv1gIvVNltIKVWeEseA
提取码:wff0