1
votes

I have a spring-boot project in which I am transitioning from Log4j to Log4j2. I have followed the steps in the documentation here. Specifically, I have modified my log4j.xml to cohere with log4j2 standards and renamed it log4j2.xml I have enabled debugging on log4j2 by using the <Configuration status="debug"> setting in my log4j2.xml so I can see log4j2 startup. On startup of my spring boot app, I use the following system settings:

-Dlog4j.configurationFile=log4j2.xml -Dorg.jboss.logging.provider=log4j2

I can see my log4j2.xml in the debug output starting the appenders, etc, and then final log4j2 message stating:

Logging provider: org.jboss.loggin.Log4j2LoggerProvider found via system property

I am using the following jars:

compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.12'

compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.4.1'

compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '1.4.0.RELEASE'

However, I am still receiving messages from Log4j:

log4j:WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system properly log4j WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info

So my underlying question is how to shut off log4j and only use log4j2? Is there a message I will receive from log4j2 that will explicitly tell me when I have properly configured it correctly? Is there any special configurations I am missing to use Log4j2?

3
remove the logging dependencies all but the spring-boot-starter-log4j2 one.M. Deinum

3 Answers

1
votes

You have to use only these dependencies for log4j2.

<dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>${log4j.slf4j.impl.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>${log4j2.version}</version>
            <scope>runtime</scope>
        </dependency>

Also you need to exclude spring-boot-starter-logging from spring-boot. like this

0
votes

The Log4j2 FAQ now has an item on excluding conflicting dependencies.

I think you need this:

<dependencies>
  <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
    <scope>provided</scope>
  </dependency>
</dependencies>
0
votes

My project is using log4j2 with spring-boot.

The below is a part of pom.xml. Please try it.

<dependencies>
    <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-log4j2</artifactId>
    </dependency>
</dependencies>