【问题标题】:Disable automatic logging configuration in spring boot在 Spring Boot 中禁用自动日志记录配置
【发布时间】:2014-07-30 14:19:24
【问题描述】:

我使用 spring boot 1.2.1.RELEASE 并注意到 spring 在启动时会自动更改我的 log4j 配置。

这是我的(弹簧)依赖项:

<!-- parent includes slf4j and log4j -->
<dependencies>
    <dependency>
        <!-- Import dependency management from Spring Boot -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>1.1.2.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.1.2.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <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-jetty</artifactId>
        <version>1.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>de.komoot.wanderwalter</groupId>
        <artifactId>wanderwalter-api-models</artifactId>
        <version>1.26-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>de.komoot.wanderwalter</groupId>
        <artifactId>wanderwalter-routing</artifactId>
        <version>1.26-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.graphhopper</groupId>
        <artifactId>graphhopper</artifactId>
        <version>0.3-kmt</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
</dependencies>

<dependencyManagement>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.8</version>
        </dependency>
    </dependencies>
</dependencyManagement>

当我使用 -Dlog4j.configuration=log4j-live.xml -Dlog4j.debug 启动我的应用程序时,我可以看到首先使用了我的 log4j 配置,然后 spring 清理它并安装它自己的配置,然后(这就是我的猜测)从类路径中添加默认 log4j.xml .

如何仅使用默认的 log4j 行为,或者如何定义 spring 将使用哪些文件进行配置?

干杯,

一月

【问题讨论】:

    标签: java spring log4j spring-boot


    【解决方案1】:

    Spring Boot 使用与日志系统无关的属性来覆盖默认配置:

    If the environment contains a property logging.config then that will be used to initialize the logging system, otherwise a default location is used.

    所以请改用-Dlogging.config=log4j-live.xml -Dlog4j.debug

    【讨论】:

    • 非常感谢,我“只”检查了文档,而不是 java 文档。很好地隐藏了那面旗帜。我会试一试,然后告诉你。
    • 该属性在参考文档中也是described
    • 终于按预期工作了。 (即使使用 --logging.config 对独立应用程序看起来更好)。我使用 classpath:log4j-custom.xml 作为值。
    • --logging.config=../etc/log4j.xml 对我有用,但 -Dlogging.config=../etc/log4j.xml 没有,使用 spring boot 1.3.0。 RELEASE 和 log4j 1.2.17
    猜你喜欢
    • 1970-01-01
    • 2015-06-24
    • 2019-08-30
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    相关资源
    最近更新 更多