前言
Spring Boot 默认使用Logback,来打印日志,这里还想说的SLFJ(Simple Logging Facade for Java),它们之间的关系,一张图,说明一切:
maven 配置
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-logging
org.springframework.boot
spring-boot-starter-log4j2
org.apache.logging.log4j
log4j-flume-ng
2.6
log4j2.xml 配置
Log4j2 提供非常丰富的Appender,比如CassandraAppender,AsyncAppender,我们这里配置了简单的Flume Appnder,Failover Appender.
api-web %d{yyyy-MM-dd HH:mm:ss.SSS} [%X{userId}] [%t] [%-5level] %c{1.}@%M%L - %m%n ${log-pattern} ${log-pattern} ${log-pattern}
总结
如果遇到识别不了log4j2.properties/xml,可以在application.properties,中指定 logging.config=classpath:log4j2.properties/xml
参考
https://springframework.guru/introducing-log4j-enterprise-class-logging/
http://logging.apache.org/log4j/2.x/manual/appenders.html#RollingFileAppender
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网



