spring日志的选择

common-logging

在springframework的spring-core中强制指定了使用common-logging模块,该模块是标准的实现至Jarka Common Log(JCL)的,并在runtime运行时自动发现其它框架选择的日志组件,并定位一个认为最接近的日志组件作为应用日志(如果什么都没找到,会使用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排除,同时需要使用SL4J桥接,将springframework的common-logging桥接到SL4J上,所以需要4个依赖,同时排除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时不需要排除spring-core中的common-logging,同时log4j也是运行时绑定,相当于common-logging在运行时绑定了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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容