在spring boot中禁用自动日志记录配置 [英] Disable automatic logging configuration in spring boot

查看:194
本文介绍了在spring boot中禁用自动日志记录配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use spring boot 1.2.1.RELEASE and noticed that spring automatically changes my log4j configuration on startup.

这是我的(spring)依赖项:

Here are my (spring) dependencies:

<!-- 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 。

When I start my application with -Dlog4j.configuration=log4j-live.xml -Dlog4j.debug I can see that first my log4j config is used, then spring cleans it and installs its own config and then (this is what I guess) adds the default log4j.xml from the classpath.

我如何只使用默认的log4j行为,或者如何定义我的哪些文件将用于配置?

How can I use only the default log4j behavior or how can I define which of my files spring shall use for configuration?

干杯,

Jan

推荐答案

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

Spring Boot uses a logging system-agnostic property to override the default configuration:


如果环境包含属性 logging.config 然后将用于初始化日志系统,否则使用默认位置。

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

这篇关于在spring boot中禁用自动日志记录配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆