gpt4 book ai didi

java - 错误 StatusLogger Log4j2 找不到日志记录实现

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:00:20 25 4
gpt4 key购买 nike

我正在尝试实现 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 中添加的项目和依赖项:

enter image description here

enter image description here

感谢任何帮助。

最佳答案

此依赖项有助于避免 lambda 的此错误。

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

关于java - 错误 StatusLogger Log4j2 找不到日志记录实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47881821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com