Issues exposing Http Client logs with Log4j2

时间:2019-05-27 09:01:11

标签: java maven http log4j2 apache-httpclient-4.x

Problems exposing HTTP client logs through Log4j2. I was able to expose the logs with log4j v1, but it's not working with log4j2.

Checked the transactive dependencies of http client v4 and it uses common logging. So I passed log4j-jcl.jar at runtime since its a bridge. But it's not working

Dependencies used:

Http Dependencies:

<dependency>
                <groupId>com.dictao.util</groupId>
                <artifactId>dictao-util-net</artifactId>
                <version>${dictao.common.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.6</version>
           </dependency>
           <dependency>
            <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpmime</artifactId>
                <version>4.5.6</version>
           </dependency>

Bridge Dependency:

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-jcl</artifactId>
  <version>2.11.2</version>
<scope>runtime</scope>
</dependency> 

For Log4j1:

log4j.logger.org.apache.http.impl.conn=DEBUG 
log4j.logger.org.apache.http.impl.client=DEBUG 
log4j.logger.org.apache.http.client=DEBUG 
log4j.logger.org.apache.http=DEBUG 

Passing the same thing in Log4j2,but no result.

Output: No error and no log file is generated.

1 个答案:

答案 0 :(得分:1)

您需要将log4j-core添加到您的依赖项中

Log4j2分为api和核心模块(而log4j1是单语言的)。 添加桥依赖项时,仅可传递地仅获取log4j2 api,但没有实际的日志记录引擎(log4j-core模块)。

支持我的话:http://central.maven.org/maven2/org/apache/logging/log4j/log4j-jcl/2.11.2/log4j-jcl-2.11.2.pom