Kartik
Kartik

Reputation: 7917

log4j 2 not showing dependency logs

I am using apache HttpClient to execute a POST request:

CloseableHttpResponse response = HttpClients.createDefault().execute(request);

I want to see the request (and other apache client library log statements) in the logs, but I can only see my application logs, no other logs from any dependency.

Here is my log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Lambda name="Lambda">
            <PatternLayout>
                <pattern>%d %X{AWSRequestId} %t %-5p [%X{userId}] %c{1}:%L - %m%n</pattern>
            </PatternLayout>
        </Lambda>
    </Appenders>
    <Loggers>
        <Logger name="org.apache.http" level="debug">
            <AppenderRef ref="Lambda"/>
        </Logger>
        <Root level="debug">
            <AppenderRef ref="Lambda"/>
        </Root>
    </Loggers> 
</Configuration>

Using this answer, I added the following, but it still doesn't show the apache logs.

    <Logger name="org.apache.http.client" level="debug">
        <AppenderRef ref="Lambda"/>
    </Logger>
    <Logger name="org.apache.http.impl.client" level="debug">
        <AppenderRef ref="Lambda"/>
    </Logger>
    <Logger name="org.apache.http.impl.conn" level="debug">
        <AppenderRef ref="Lambda"/>
    </Logger>

I can confirm that this log4j2.xml is being used by log4j because the logs are following the <pattern> I wrote.

What am I missing? Please help.

Upvotes: 4

Views: 2066

Answers (1)

Kartik
Kartik

Reputation: 7917

Adding the Commons Logging Bridge dependency fixed it:-

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jcl</artifactId>
        <version>2.11.0</version>
    </dependency>

See this for more details.

Upvotes: 5

Related Questions