我正在尝试实现 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 中添加的项目和依赖项:
任何帮助表示赞赏。
原文由 Alok 发布,翻译遵循 CC BY-SA 4.0 许可协议
通过设置 log4j2 配置文件的系统属性解决了错误消息。下面是下面的代码。