Spring boot: ERROR StatusLogger Log4j2 could not find a logging implementation
Asked Answered
M

2

4

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

Mhd answered 30/5, 2019 at 12:45 Comment(1)
Found the answer you just need to delete your JARS and re download it. As I am using Maven I have deleted m2\repository\org\apache\logging\log4j folder. Its working fine for me. Ans link https://mcmap.net/q/730538/-log4j2-could-not-find-a-logging-implementation-with-spring-bootMhd
S
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.

Swoosh answered 28/5, 2020 at 7:13 Comment(2)
The question was about how to get log4j 2 working, not eliminate using it.Hadden
This is not working for meMisappropriate
T
0

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

Tackle answered 11/5, 2022 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.