https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/#boot-features-logginghtml
https://logging.apache.org/log4j/2.x/manual/configuration.htmlspring
Spring Boot 默認使用logback,要改用log4j得apache
先:spring-boot
<!-- 排除默認日誌包 --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
再:
<!-- 添加log4j包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>
spring-boot-starter-log4j2會傳遞依賴
log4j-core
log4j-slf4j-impl
jcl-over-slf4j
jul-to-slf4j
而後:
添加
log4j2-spring.xml, log4j2.xml
配置文件或者添加log4j2.yml配置文件spa
<!-- 加上這個才能辨認到log4j2.yml文件 --> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-yaml</artifactId> </dependency>
參考文章:http://blog.csdn.net/shangmingtao/article/details/77517177.net