错误StatusLogger Log4j2找不到日志记录实施 [英] ERROR StatusLogger Log4j2 could not find a logging implementation

查看:1939
本文介绍了错误StatusLogger Log4j2找不到日志记录实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现 log4j 2 ,但是它始终抛出以下错误.

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.

这是我要运行的代码.

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配置文件的系统属性来解决该错误消息.下面是下面的代码.

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

这篇关于错误StatusLogger Log4j2找不到日志记录实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆