Kunal Malhotra
Kunal Malhotra

Reputation: 51

Issues exposing Http Client logs with Log4j2

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.

Upvotes: 0

Views: 404

Answers (1)

Lesiak
Lesiak

Reputation: 25936

You need to add log4j-core to your dependencies

Log4j2 is divided into api and core module (whereas log4j1 was monolitihic). When you add your bridge dependency, you transitively pull in only log4j2 api, but there is no actual logging engine (log4j-core module).

To back my words: http://central.maven.org/maven2/org/apache/logging/log4j/log4j-jcl/2.11.2/log4j-jcl-2.11.2.pom

Upvotes: 1

Related Questions