外部log4j配置在Spring Boot中不起作用

时间:2017-10-09 21:51:16

标签: java maven spring-boot log4j2 netflix-zuul

我正在使用Spring Boot(war包装),Zuul和log4j,我的依赖项设置为spring文档说。

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <scope>provided</scope>
        <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>
        <scope>provided</scope>
    </dependency>
<dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-yaml</artifactId>
        <scope>provided</scope>
    </dependency>

我正在使用共享库,因此我的依赖项提供了范围。

这里的问题是当我将log4j2.yml配置放在我的classpath(resources文件夹)中时,一切正常,但是当我的配置在应用程序之外时,它不起作用(只创建日志文件)。

logging:
  config: ../path/log4j2.yml

我的服务器日志告诉我:

DEBUG Started configuration YamlConfiguration[location=../path/log4j2.yml] 
OK.
TRACE Stopping YamlConfiguration[location=../path/log4j2.yml]...
TRACE YamlConfiguration notified 4 ReliabilityStrategies that config will be 
stopped.
TRACE YamlConfiguration stopping 3 LoggerConfigs.
TRACE YamlConfiguration stopping root LoggerConfig.
TRACE YamlConfiguration notifying ReliabilityStrategies that appenders will 
be stopped.
TRACE YamlConfiguration stopping remaining Appenders.
TRACE YamlConfiguration stopped 3 remaining Appenders.
TRACE YamlConfiguration cleaning Appenders from 4 LoggerConfigs.

除此之外,当我不使用SLF4J(例如apache commons logging)时,它可以工作!

0 个答案:

没有答案