spring boot + slf4j + log4j配置

https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/#boot-features-logging

https://logging.apache.org/log4j/2.x/manual/configuration.html

Spring Boot 默认使用logback,要改用log4j得

先:

<!-- 排除默认日志包 -->
      <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配置文件

 

<!-- 加上这个才能辨认到log4j2.yml文件 -->
    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-yaml</artifactId>
    </dependency>

参考文章:http://blog.csdn.net/shangmingtao/article/details/77517177

 

posted @ 2017-11-15 08:52  JillWen  阅读(6285)  评论(0编辑  收藏  举报