spring日志的選擇

common-logging

在springframework的spring-core中強(qiáng)制指定了使用common-logging模塊,該模塊是標(biāo)準(zhǔn)的實(shí)現(xiàn)至Jarka Common Log(JCL)的,并在runtime運(yùn)行時(shí)自動(dòng)發(fā)現(xiàn)其它框架選擇的日志組件,并定位一個(gè)認(rèn)為最接近的日志組件作為應(yīng)用日志(如果什么都沒(méi)找到,會(huì)使用JDK的LOG,(java.util.logging or JUL for short)),在maven中只需要配置了spring-core就有了

<dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.2.5.RELEASE</version>
  </dependency>
</dependencies>

SLF4J

使用SLF4J(Simple Log Factory For JAVA)需要將common-logging排除,同時(shí)需要使用SL4J橋接,將springframework的common-logging橋接到SL4J上,所以需要4個(gè)依賴,同時(shí)排除spring-core中自帶的common-logging,使用maven如下

<dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.2.5.RELEASE</version>
    <exclusions>
      <exclusion>
         <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>1.5.8</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.5.8</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.8</version>
  </dependency>
  <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
  </dependency>
</dependencies>

log4j

使用log4j時(shí)不需要排除spring-core中的common-logging,同時(shí)log4j也是運(yùn)行時(shí)綁定,相當(dāng)于common-logging在運(yùn)行時(shí)綁定了log4j,maven如下

<dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.2.5.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
  </dependency>
</dependencies>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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