log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment)

22,808

The message

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.

is coming from log4j1. You must still have the jar on your classpath. Run "mvn dependency:tree" and see what is bringing it in and then add an exclude for it.

Share:
22,808

Related videos on Youtube

Amer Qarabsa
Author by

Amer Qarabsa

Software engineer/Architect with 7 years of experience in various backend/Frontend technologies

Updated on February 18, 2020

Comments

  • Amer Qarabsa
    Amer Qarabsa about 4 years

    I am trying to use log4j2.xml instad of log4j but I keep getting

    log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
    log4j:WARN Please initialize the log4j system properly.
    

    File is located under src/main/resources

     <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="warn" name="WIP">
      <Appenders>
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %MDC{threadTrackId} %40c{1.} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="warn">
            <AppenderRef ref="console"/>
        </Root>
        <Logger name="com.test" level="debug"/>
        <Logger name="org.springframework" level="info"/>
    </Loggers>
    </Configuration>
    

    I am not sure if the file is being located correctly but the appenders inside it are not read correctly or the file is not being located.

    in My pom file I have the following dependencies

    <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
    <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-1.2-api</artifactId>
        </dependency>
    

    And this is my build section in pom

      <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.wirecard.wip.db.RecreateDatabase</mainClass>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    In my class this is how I initialize my logger

    private static final Logger LOG =   LoggerFactory.getLogger(MyClass.class);
    

    and my imports are

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    

    I run my class through maven using this command

    mvn -B -f pom.xml exec:java -Dlog4j.configurationFile=log4j2.xml
    

    I also tried

    mvn -B -f pom.xml exec:java -Dlog4j.configurationFile=classpath:log4j2.xml
    

    Any help is appreciated

    • Alexey R.
      Alexey R. over 6 years
      Are you trying to use just log4j2.xml with the actually old log4j libs? You might be setting up libs dependencies incorreclty. Check this topic stackoverflow.com/questions/25386651/…
    • Amer Qarabsa
      Amer Qarabsa over 6 years
      @AlexeyR. I already tried this
  • Amer Qarabsa
    Amer Qarabsa over 6 years
    yes actually that was the problem , I figured it out several days ago abut forgot to post an answer , thanks for your help
  • Bruce wayne - The Geek Killer
    Bruce wayne - The Geek Killer over 2 years
    i also faced same problem, i had a jar that pointed to log4j1 in my classpath. I traced that jar and found that it was indirectly coming from another jar. Excluded that inner jar and built once again. Now it is working. Thanks.