如何使用 log4j2 Commons Logging Bridge

How to use log4j2 Commons Logging Bridge

我想在 commons 1.2 中使用 log4j2 Commons Logging Bridge。我尝试使用如下内容:

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

public class MyClass{

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

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

log4j:WARN Please initialize the log4j system properly.

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

您可能需要查看 which jars you need 上的常见问题页面。

您将需要类路径中的以下 jar:

  • log4j-api-2.2
  • log4j-core-2.2
  • log4j-jcl-2.2
  • 公共日志记录

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