spring引导的logging.config配置

spring引导的logging.config配置,spring,logging,log4j,spring-boot,logback,Spring,Logging,Log4j,Spring Boot,Logback,我想在我的spring boot应用程序中配置log4j.xml文件的位置。 为此,我在application.properties配置中添加了logging.config属性,指示log4j.xml文件路径。 但似乎这个属性被忽略了。 但它应该根据spring boot文档工作: logging.config= # location of config file (default classpath:logback.xml for logback) 我做错什么了吗?Spring Boot包含

我想在我的spring boot应用程序中配置log4j.xml文件的位置。 为此,我在application.properties配置中添加了logging.config属性,指示log4j.xml文件路径。 但似乎这个属性被忽略了。 但它应该根据spring boot文档工作:

logging.config= # location of config file (default classpath:logback.xml for logback)

我做错什么了吗?

Spring Boot包含一些启动器,如果您想排除或交换特定的技术方面,可以使用这些启动器。默认情况下,如果要在类路径中使用
log4j
add
spring-boot-starter-log4j
,它将使用
logback
。例如,对于maven,它将是这样的:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
            <version>1.2.4.RELEASE</version>
</dependency>

我发现在某些情况下,外部日志配置(logback.xml)不会被忽略:当应用程序从应用程序文件夹启动时,它可以正常工作。 关于这一点的一些说明:应用程序是通过脚本运行的,可以从任何地方调用脚本。 我还没有深入了解它为什么会以这种方式工作,但如果我在启动期间提供配置文件路径作为参数,它就会工作。因此,我们只需将此参数添加到运行脚本: --spring.config.location=/configPath/application.properties 这个问题可能是由弹簧加载阶段引起的。 如果您知道此问题的根本原因,请根据以下内容分享:)

如果您使用starter POM来组装依赖项,这意味着您必须排除Logback,然后包含您选择的Log4j版本

像这样:

<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>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
</dependency>

org.springframework.boot
弹簧靴起动器
org.springframework.boot
spring启动程序日志记录
org.springframework.boot
spring-boot-starter-log4j

logging.config的属性值是多少?这是指向my logback.xml的完整路径。
logging.config = classpath:path/to/log4j.xml
<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>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
</dependency>