将log4j2与slf4j一起使用 [英] Using log4j2 with slf4j
本文介绍了将log4j2与slf4j一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我尝试了这个(非maven实施)和要求他们的网站,用于将slf4j添加到log4j。并尝试使用此代码
So I have tried following this (non-maven implementation) and requirements in their web site for adding slf4j to log4j. and tried using this code
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger(Main.class);
logger.info("test");
}
并将以下内容添加到我的库中
and added the following to my library
- log4j-api-2.3.jar
- log4j-core-2.3.jar
- log4j -sl4j-impl-2.3.jar
- log4j-to-sl4j-2.3.jar
- slf4j-api-1.7.12.jar
- log4j-api-2.3.jar
- log4j-core-2.3.jar
- log4j-sl4j-impl-2.3.jar
- log4j-to-sl4j-2.3.jar
- slf4j-api-1.7.12.jar
当我尝试运行它时出现以下错误
when I try running it I get the following error
Exception in thread "main" java.lang.StackOverflowError
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964)
at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:40)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:284)
at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:284)...
知道我哪里出错吗?
推荐答案
你正在用<$创建一个调用循环c $ c> log4j-slf4j-impl-2.3.jar 和 log4j-to-slf4j-2.3.jar
。
log4j-slf4j-impl-2.3.jar
是将slf4j调用发送到log4j的适配器的实现。
log4j-slf4j-impl-2.3.jar
is the implementation of the adapter that sends slf4j calls to log4j.
log4j-to-slf4j-2.3.jar
正在发送log4j调用回到slf4j。 删除此。
log4j-to-slf4j-2.3.jar
is sending log4j calls right back to slf4j. Remove this one.
这篇关于将log4j2与slf4j一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文