无法使用apache httpComponent和log4j2输出日志

时间:2016-03-21 15:19:06

标签: java maven log4j2 apache-httpcomponents

我希望在控制台中输出httpComponent从Apache发送的请求。我在log4j2.xml中尝试了几个配置,但从来没有在控制台中找到与http相关的内容。我只看到我的日志应用程序。

这是我的log4j2.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <!--PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/-->
            <PatternLayout pattern="* %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Console"/>
        </Root>

        <logger name="org.apache.http" level="debug"/>
        <logger name="org.apache.wire" level="debug"/>
    </Loggers>
</Configuration>

这是我的小代码

public ApiResponse<DealDiscovery> execute() throws IOException {
        HttpClient client = HttpClientBuilder.create().build();
        URI uri = null;
        try {
            uri = new URIBuilder(BASE_URL).addParameter(TOKEN, token).build();
        } catch (URISyntaxException e) {
            //Should never happened
        }
        HttpGet http = new HttpGet(uri);
        HttpResponse httpResponse = client.execute(http);
        String response = EntityUtils.toString(httpResponse.getEntity());
        return parseResponse(response);
    }

这是我在pom.xml中的依赖

    <dependency>
        <groupId>com.saucelabs</groupId>
        <artifactId>sauce_junit</artifactId>
        <version>2.1.20</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.6.2</version>
    </dependency>

    <dependency>
        <groupId>org.skyscreamer</groupId>
        <artifactId>jsonassert</artifactId>
        <version>1.2.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-junit</artifactId>
        <version>2.0.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>19.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.8.3</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.13</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.13</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient-cache</artifactId>
        <version>4.5.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.5.2</version>
    </dependency>

</dependencies>

我错过了什么?

0 个答案:

没有答案