'Spring boot: ERROR StatusLogger Log4j2 could not find a logging implementation

I trying to add log4j2 to spring boot project but it is giving below error. ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console

I have configured same using this link https://howtodoinjava.com/spring-boot2/spring-boot-log4j2-config/

package log.demo.LogDemo;

/**
 * Hello world!
 *
 */
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {


    private static final Logger LOGGER = LogManager.getRootLogger();//Application.class);

    public static void main(String[] args)
    {

        ApplicationContext ctx = SpringApplication.run(Application.class, args);

        LOGGER.info("Info level log message");
        LOGGER.debug("Debug level log message");
        LOGGER.error("Error level log message");
    }
}
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>log.demo</groupId>
    <artifactId>LogDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>LogDemo</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <!-- <exclude>application.properties</exclude> <exclude>TahitiConfig.xml</exclude> 
                        <exclude>job_definitions.xml</exclude> -->
                </excludes>
            </resource>
        </resources>

    </build>
</project>

Don't understand what went wrong any help will be great. Please let me know if required more information

Tried this solution but no help Log4j2 could not find a logging implementation with Sprint Boot



Solution 1:[1]

Add dependency to your pom

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-to-slf4j</artifactId>
    <version>2.8.2</version>
</dependency>

This is because for my case the log4j is printing from Elasticsearch. I have implemented logback.xml for logging. To overcome default log4j error messages, you can override with slf4j.

Solution 2:[2]

I have this problem in NetBeans 8.0 when I added the jar log4j-api-2.12.2.jar.

Netbeans print this message in the console.

"StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console..."

I resolved this problem when I added log4j-core-2.12.2.0001L.jar in my project.

I supposed in Spring, just most add the dependency log4j-core in maven.


Link download JAR

https://jar-download.com/?search_box=log4j-core

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2