'ERROR StatusLogger Log4j2 could not find a logging implementation
I am trying to implement log4j 2 but it keeps throwing the following error.
> ERROR StatusLogger Log4j2 could not find a logging implementation.
> Please add log4j-core to the classpath. Using SimpleLogger to log to
> the console...
> ERROR LogExample This Will Be Printed On Error
> FATAL LogExample This Will Be Printed On Fatal
I have tried the solution given on the net. But the don't seem to be working for me.
This is the code that I am trying to run.
package demo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LogExample {
private static final Logger LOG = LogManager.getLogger(LogExample.class);
public static void main(String[] args) {
LOG.debug("This Will Be Printed On Debug");
LOG.info("This Will Be Printed On Info");
LOG.warn("This Will Be Printed On Warn");
LOG.error("This Will Be Printed On Error");
LOG.fatal("This Will Be Printed On Fatal");
LOG.info("Appending string: {}.", "Hello, World");
}
}
Project and dependency added in the pom.xml:
Any help is appreciated.
Solution 1:[1]
This dependency help to avoid this error from lambda.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.8.2</version>
</dependency>
Solution 2:[2]
if you already added log4j-core to maven pom, you dont need anything more it should work. Problem could be with your IDE, that does not see your maven dependency. Try reloading or reimporting maven dependencies, or restarting your IDE also can help.
Solution 3:[3]
To get around a similar issue with Spring Boot I added
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
to my POM
Solution 4:[4]
In my case the error was related with the version of maven-shade-plugin (3.2.2).
It works when I set this plugin to version 3.2.1
Solution 5:[5]
I was facing the same issue for upgrading log4j from 1.x to Log4j-2.17.1. Was getting this error while deploying to GlassFish server.
I took the following steps to correct this:
Disbled the autoInitialization of Log4j2. Added to web.xml
<context-param> <param-name>isLog4jAutoInitializationDisabled</param-name> <param-value>true</param-value> </context-param>Initialized Log4j2 programmatically:
InputStream inputStream = new FileInputStream("path of Log4j2.xml"); ConfigurationSource source = new ConfigurationSource(inputStream); Configurator.initialize(null, source);
Solution 6:[6]
I haved this problem in NetBeans 8.2 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, you just most add the dependency log4j-core in maven.
Link download JAR
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 | engKocer |
| Solution 3 | rupweb |
| Solution 4 | dvillaj |
| Solution 5 | EJoshuaS - Stand with Ukraine |
| Solution 6 | Andronicus |


