Spring Boot忽略logback-spring.xml [英] Spring Boot ignoring logback-spring.xml
问题描述
我有2个使用Logback的Spring Boot(1.4.1-RELEASE)控制台应用程序。两个配置文件或多或少相同,位于我的 / src / main / resources 文件夹中,并命名为 logback-spring.xml 。
I have 2 Spring Boot (1.4.1-RELEASE) console applications using Logback. Both configuration files are more or less identical, are located in my /src/main/resources folder and named logback-spring.xml.
两个项目都在其pom.xml中包含maven依赖项spring-boot-starter-logging并获取logback版本1.1.7。
Both projects include the maven dependency spring-boot-starter-logging in their pom.xml and fetch the logback Version 1.1.7.
两个poms中定义的Spring Boot配置:
The Spring Boot config as defined in both poms:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath />
</parent>
<groupId>d.m.v.app-a</groupId>
<artifactId>my-app-a</artifactId>
<version>1.0.16-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
然而,在运行应用程序时,其中一个似乎完全忽略了logback配置而另一个选择了它像预期的那样。
However, when running the applications one of them seems to fully ignore the logback configuration while the other picks it up like expected.
如果我将文件名更改为 logback.xml ,对于无法正常工作的应用程序,它突然正常工作(即使使用弹簧配置文件)我正在使用它们。)
If I change the filename to logback.xml for the application that didn't work properly it suddenly works fine (even with the spring profiles that I'm using in them).
所涉及的任何配置(意味着pom.xml,application.properties等)没有明显的区别。
There is no apparent difference in any of the configurations involved (meaning the pom.xml, application.properties, etc.).
有人知道为什么会这样吗?我发现这种行为相当令人困惑。
Does anybody know why that might be the case? I find this behaviour rather confusing.
推荐答案
我知道它有些陈旧,但我有同样的问题并想出来了。 ..所以原因只是你的类路径上有一个logback.xml(在某个地方,不一定在你开始的项目中,在我的情况下它是一个依赖项)。
I know it is somewhat old, but i had the same issue and figured it out... so the reason is simply that you have a logback.xml on your classpath (somewhere, not necessarily in your project which you start, in my case it was a dependency).
看看这里: org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(LoggingInitializationContext,LogFile)
设置一个断点,然后你会看到。
set a breakpoint, then you will see.
如果spring boot没有找到任何logback配置(logback-test.groovy,logback-test。类路径上的xml,logback.groovy,logback.xml)将被选中logback-spring.xml。
If spring boot doesn't find any logback configurations ("logback-test.groovy", "logback-test.xml", "logback.groovy", "logback.xml") on the classpath, logback-spring.xml will be picked up.
这篇关于Spring Boot忽略logback-spring.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!