ERROR StatusLogger Log4j2无法找到一个日志实现。[英] ERROR StatusLogger Log4j2 could not find a logging implementation

本文是小编为大家收集整理的关于ERROR StatusLogger Log4j2无法找到一个日志实现。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在尝试实现 log4j 2 ,但它一直丢下以下错误.

> 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

我尝试了网上给出的解决方案.但是似乎对我不起作用.

这是我要运行的代码

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");
    }

}

pom.xml中添加的项目和依赖性:

在此处输入图像描述

在此处输入图像描述

任何帮助都将不胜感激.

推荐答案

通过设置log4j2配置文件的系统属性来解决错误消息.以下是以下代码.

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

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

其他推荐答案

这种依赖性有助于避免lambda的错误.

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

其他推荐答案

如果您已经在Maven POM中添加了Log4J核,那么您不需要任何其他功能.问题可能在于您的IDE,这不会看到您的Maven依赖性.尝试重新加载或重新接收Maven依赖性,或重新启动您的IDE也可以帮助您.

本文地址:https://www.itbaoku.cn/post/1575175.html

问题描述

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.

推荐答案

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());

其他推荐答案

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>

其他推荐答案

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.