美文网首页
slf4j 的 桥接器和适配器

slf4j 的 桥接器和适配器

作者: 周紫一 | 来源:发表于2021-03-27 20:22 被阅读0次

    1.桥接器

            A. log4j --> slf4j
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>log4j-over-slf4j</artifactId>
                <version>2.0.0-alpha1</version>
            </dependency>
    
           B. log4j2 --->slf4j
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-to-slf4j</artifactId>
                <version>2.14.1</version>
            </dependency>
    
           C. jul--->slf4j
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jul-to-slf4j</artifactId>
                <version>2.0.0-alpha1</version>
            </dependency>
          
           D. jcl --->slf4j
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>2.0.0-alpha1</version>
            </dependency>
    
    

    A. log4j-over-slf4j 桥接方式,定义一套和log4j 一样的api ,在这套api中 再调用slf4j的api
    app ---> log4j-over-slf4j --->slf4j-api

    image.png
    image.png

    B. log4j-to-slf4j 的桥接方式 使用了spi 标准, 此处slf4j 是作为适配器存在的
    app --->log4j-api-2.X ---> log4j-to-slf4j --->slf4j-api
    所以 log4j-api-2.X 这个包是必须的,不可剔除

    image.png

    2.适配器(也就是具体的日志记录策略)

         A. jul
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-jdk14</artifactId>
                <version>2.0.0-alpha1</version>
            </dependency>
    
        B. log4j
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>2.0.0-alpha1</version>
            </dependency>
          
        C.log4j2
             <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-slf4j-impl</artifactId>
                <version>2.14.1</version>
            </dependency>
    
        D. logback
             <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.3.0-alpha5</version>
            </dependency>
    

    3.具体实现

    B. log4j
             <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
    
    C.log4j2
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>2.14.1</version>
            </dependency>
    

    相关文章

      网友评论

          本文标题:slf4j 的 桥接器和适配器

          本文链接:https://www.haomeiwen.com/subject/mluyhltx.html