Spring Boot 項目 logback 升級 log4j2

今天把一個Spring Boot的日志框架由默認的logback升級為log4j2, 過程如下:

  1. 導包
  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
  1. 寫配置
    在resources下增加log4j2.xml的配置文件
  2. 啟動
    正常情況下控制臺日志樣式已經(jīng)發(fā)生了變化
    臥槽怎么沒變化???什么情況, 怎么破...
    看項目啟動時控制臺打印如下
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/kayz/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/kayz/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

明明我已經(jīng)排除了這么還是綁定上了logback?? 說明還是有其他包引了logback..
使用 mvn dependency:tree 分析一下:

[INFO] +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.15.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.15.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.15.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework:spring-aop:jar:4.3.18.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:4.3.18.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjweaver:jar:1.8.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:1.5.15.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.18.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:4.3.18.RELEASE:compile
[INFO] |  \- org.springframework:spring-context-support:jar:4.3.18.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.15.RELEASE:compile

發(fā)現(xiàn)aop這個包搗的鬼, 接著排除

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

問題解決

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容