3

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

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>

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.

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

Cheers,

Jan

3 Answers 3

4

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

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

So use -Dlogging.config=log4j-live.xml -Dlog4j.debug instead.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot, I was "only" checking the documentation but not the java doc. Well hidden that flag. I'll give it a try and let you know.
That property is described in the reference documentation as well.
That finally works as expected. (even with --logging.config which looks much nicer for standalone applications). I used classpath:log4j-custom.xml as value.
--logging.config=../etc/log4j.xml work for me , but -Dlogging.config=../etc/log4j.xml did not , with spring boot 1.3.0.RELEASE , and log4j 1.2.17
0

I had similar issue in following setup:

  • spring boot 2.7.3
  • spring 5.3.22
  • log4j 2.18

log4j-1 Configuration (and API usage) bridged to log4j2 by log4j-1.2-api artifact (and defining "-Dlog4j1.compatibility=true" on command line)

Defining logging.config (ponting to V1 log4j.xml) as celkins suggests did not help, since the reconfiguration by spring even failed because the implementation was not aware for log4j V1 configuration syntax (sax parse error).

My solution was:

Setting the command line property

-Dorg.springframework.boot.logging.LoggingSystem=none

This lets spring instantiate a NoOp LoggingSystem which does nothing.

Comments

0

To fix it, add a NopStatusListener like this :

<!-- Stop output INFO at start -->
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>
            %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
        </Pattern>
    </layout>
</appender>

<root level="error">
    <appender-ref ref="STDOUT"/>
</root>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.