如何使用log4j2 Commons Logging Bridge

Gra*_*ant 8 java logging log4j apache-commons log4j2

我想使用log4j2 Commons Logging Bridge with commons 1.2.我尝试使用如下内容:

import org.apache.logging.log4j.jcl.LogFactoryImpl;

public class MyClass{

    private static Log log = LogFactoryImpl.getLog(DropinsBundleDeployer.class);
         .
         .
         .
    log.error("Error occured", e);
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行代码时,我遇到了问题并且看不到任何日志:

log4j:WARN Please initialize the log4j system properly.
Run Code Online (Sandbox Code Playgroud)

但是log4j2.xml文件位于类路径中.如何使用log4j2正确使用commons logging 1.2?

Rem*_*pma 12

您可能需要查看您需要的罐子的FAQ页面.

您将在类路径上需要以下jar:

  • log4j的-API 2.2
  • log4j的核心 - 2.2
  • log4j的-JCL-2.2
  • 公共伐木

另外请确保log4j-1.2 不在您的类路径中.该错误消息看起来像log4j-1.2错误...

  • 你需要commons-logging jar和log4j-jcl桥接jar. (2认同)