ERROR StatusLogger Log4j2 could not find a logging implementation

Alok :

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:

enter image description here

enter image description here

Any help is appreciated.

Alok :

Solved the error message by setting the system property for log4j2 configuration file. below is the below code.

System.setProperty("log4j.configurationFile","./path_to_the_log4j2_config_file/log4j2.xml");

Logger log = LogManager.getLogger(LogExample.class.getName());

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=431706&siteId=1