首页 文章

如何替换spring boot 2.0中的默认日志记录系统

提问于
浏览
0

我将把一个slf4j实现(基于logback的公司框架)集成到spring boot 2.0中 . 在我的进展中,我发现默认的logback依赖性与我自己的依赖项冲突 . 以这种方式排除 spring-boot-starter-logging 模块:

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

冲突的错误消失了,但似乎spring boot使用我的库作为slf4j日志记录实现,就像之前的方式一样,我的自定义函数中没有任何工作 .

我想知道是否有一种方法可以用我的代码替换日志系统以使其工作但是在spring.io网站上没有找到关于此的参考 .

3 回答

  • 0

    要禁用Spring Boot的LoggingSystem(默认为LogbackLoggingSystem),需要设置以下系统属性

    -Dorg.springframework.boot.logging.LoggingSystem=none
    

    这是在https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.htmlhttps://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html以供参考 .

  • 0

    错误

    Exception in thread "main" java.lang.StackOverflowError
        at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
    

    由log4j-sl4j-impl和log4j-to-sl4j的call-loop生成 .

    你可以解决不包括log4j到slf4j:

    configurations {
            all*.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
        }
    
  • 0

    Remove login default dependency in the Spring-boot-starter-web project

    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>
    

    我们需要在类路径中放置一个名为以下属性文件之一的文件,然后重新启动项目

    • log4j2-spring.xml

    • log4j2.xml

相关问题