Enable debug logging for Log4J2 + Apache HttpClient

廉价感情. 提交于 2019-12-05 03:35:29

I am assuming that httpcomponents use log4j-1.2 internally. Log4j2 provides an adapter that routes calls from your application that use the 1.2 API to the new 2.0 implementation.

To enable this, you only need to add log4j-core and log4j-1.2-api jars to your classpath. (Your current Maven dependencies only has log4j-api, which is the new 2.0 API.) See also http://logging.apache.org/log4j/2.x/faq.html .

Remko is right that the issue is httpcomponents using log4j-1.2 internally. The adaptor that routes log4j 1.2 to log4j 2 is called the log4j 1.2 bridge and is described here: https://logging.apache.org/log4j/2.x/log4j-1.2-api/index.html.

The maven artifacts page for log4j explains exactly how to configure your maven dependencies to include the bridge library:

Log4j 1.x API Bridge

If existing components use Log4j 1.x and you want to have this logging routed to Log4j 2, then remove any log4j 1.x dependencies and add the following.

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.5</version>
  </dependency>
</dependencies>

From https://logging.apache.org/log4j/2.x/maven-artifacts.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!