当前位置: 首页 > 知识库问答 >
问题:

Spring Boot中的多个日志实现

邢冷勋
2023-03-14

我有多模块maven项目,每当我运行它时,我都会得到以下错误:

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation

但是上面的解决方案对我都不起作用。

下面是模块的pom.xml:

<dependencies>
        <dependency>
            <groupId>com.mydomain</groupId>
            <artifactId>commons-module</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.littleshoot</groupId>
            <artifactId>proxy</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

下面是模块的依赖关系树:

 com.mydomain:circuit-module:jar:1.0-SNAPSHOT
[INFO] +- com.mydomain:commons-module:jar:1.0-SNAPSHOT:compile
[INFO] |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  +- org.postgresql:postgresql:jar:42.2.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.0.0.RELEASE:compile
[INFO] |  |  |  \- org.aspectj:aspectjweaver:jar:1.8.13:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.0.RELEASE:compile
[INFO] |  |  |  +- com.zaxxer:HikariCP:jar:2.7.8:compile
[INFO] |  |  |  \- org.springframework:spring-jdbc:jar:5.0.4.RELEASE:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:5.2.14.Final:compile
[INFO] |  |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  |  +- org.javassist:javassist:jar:3.22.0-GA:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] |  |  |  +- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  |  +- org.springframework.data:spring-data-jpa:jar:2.0.5.RELEASE:compile
[INFO] |  |  |  +- org.springframework.data:spring-data-commons:jar:2.0.5.RELEASE:compile
[INFO] |  |  |  +- org.springframework:spring-orm:jar:5.0.4.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-tx:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aspects:jar:5.0.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-mail:jar:2.0.0.RELEASE:compile
[INFO] |  |  \- com.sun.mail:javax.mail:jar:1.6.1:compile
[INFO] |  |     \- javax.activation:activation:jar:1.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-freemarker:jar:2.0.0.RELEASE:compile
[INFO] |  |  \- org.freemarker:freemarker:jar:2.3.27-incubating:compile
[INFO] |  +- commons-validator:commons-validator:jar:1.6:compile
[INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] |  |  +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-amqp:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-messaging:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework.amqp:spring-rabbit:jar:2.0.2.RELEASE:compile
[INFO] |  |     +- org.springframework.amqp:spring-amqp:jar:2.0.2.RELEASE:compile
[INFO] |  |     +- com.rabbitmq:amqp-client:jar:5.1.2:compile
[INFO] |  |     +- com.rabbitmq:http-client:jar:1.3.1.RELEASE:compile
[INFO] |  |     +- org.springframework:spring-web:jar:5.0.4.RELEASE:compile
[INFO] |  |     \- org.springframework.retry:spring-retry:jar:1.2.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.0.0.RELEASE:compile
[INFO] |  |  \- org.springframework.data:spring-data-redis:jar:2.0.5.RELEASE:compile
[INFO] |  |     +- org.springframework.data:spring-data-keyvalue:jar:2.0.5.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-oxm:jar:5.0.4.RELEASE:compile
[INFO] |  \- redis.clients:jedis:jar:2.9.0:compile
[INFO] |     \- org.apache.commons:commons-pool2:jar:2.5.0:compile
[INFO] +- org.littleshoot:proxy:jar:1.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:5.0.4.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:5.0.4.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:5.0.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-context-support:jar:5.0.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.0.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.0.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.0.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  +- net.minidev:json-smart:jar:2.3:test
[INFO] |  |  |  \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |  |     \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.15.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.7.10:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.10:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.0.4.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.5.1:test
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.5:test
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.9:test
[INFO] |  \- commons-codec:commons-codec:jar:1.11:test
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.4:test
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:test
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.4:test
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] \- org.projectlombok:lombok:jar:1.16.20:provided

共有1个答案

施令秋
2023-03-14

您可能希望从boot starter中排除日志记录,但是您可能需要为特定的日志记录框架添加依赖项。

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

以类似的方式从spring-boot-starter-logging返回或排除

 类似资料:
  • SpringBoot默认有日志输出 2017-02-27 16:04:06.644 INFO 15384 --- [ main] com.clsaa.edu.springboot.App : Starting App on eggyer with PID 15384 (D:\Data\MyCode\codeMaven\learn_springboot004\target\classes start

  • 本文向大家介绍浅谈SpringBoot是如何实现日志的,包括了浅谈SpringBoot是如何实现日志的的使用技巧和注意事项,需要的朋友参考一下 前言 休息日闲着无聊看了下 SpringBoot 中的日志实现,把我的理解跟大家说下。 门面模式 说到日志框架不得不说门面模式。门面模式,其核心为外部与一个子系统的通信必须通过一个统一的外观对象进行,使得子系统更易于使用。用一张图来表示门面模式的结构为:

  • 本文向大家介绍SpringBoot项目集成日志的实现方法,包括了SpringBoot项目集成日志的实现方法的使用技巧和注意事项,需要的朋友参考一下 SpringBoot使用Commons Logging进行所有内部日志记录,但保留底层日志实现。默认提供了Java Util Logging, Log4j2 和Logback日志配置。在每种情况下,都预先配置为使用控制台输出,并且还提供了可选的文件输出

  • 在一个使用log4j和slf4j的应用程序中,我尝试使用依赖于log4j2的elasticsearch jar。 应用程序的日志依赖项如下所示- 应用程序使用自己的<code>log4j。xml并具有一些log4j的自定义附加器,因此如果不重写附加器,则无法将其迁移到log4j2。 根据elasticsearch文档中的建议,添加了以下依赖项,以使用不同于log4j2的记录器。 但是现在在启动应用

  • 我正在使用logback.xml实现SLF4J日志记录,但应用程序正在创建多个日志文件。我需要为一个日期创建一个单一的日志文件,所有的日志级别都在相同的日志文件中。 下面是我的logback.xml配置。

  • 问题内容: 我当前正在创建一个可以包含模块的系统(将它们视为插件),其中每个模块可以拥有自己的专用日志。 我想使用log4j2项目进行日志记录,但是文件附加器似乎有些麻烦。 主项目(整个模块的模块加载器和“核心”)应具有自己的日志文件,而模块应具有自己的日志文件(如)。 通过阅读有关追加程序的文档,我发现了该类,并且我将使用它。直到我发现不能简单地将追加器添加到由创建的默认记录器中。 LogMan