配置httpclient使用logback

项目使用maven构建

1.这pom.xml里添加依赖httpclient并排除commons-logging依赖

<dependency>
    <groupId>org.apache.httpcomponentsgroupId>
    <artifactId>httpclientartifactId>
    <version>4.3.1version>
    <exclusions>
        <exclusion>
            <artifactId>commons-loggingartifactId>
            <groupId>commons-logginggroupId>
        exclusion>
    exclusions>
dependency>
2. 因为 common-logging是运行时依赖( runtime dependency),需要添加一个commons-logging 对应的SLF4J bridge 

<dependency>
    <groupId>org.slf4jgroupId>
    <artifactId>jcl-over-slf4jartifactId>
    <version>1.7.5version>
dependency>
3. 添加 SLF4J 和logback的依赖

<dependency>
    <groupId>org.slf4jgroupId>
    <artifactId>slf4j-apiartifactId>
    <version>1.7.5version>
dependency>
<dependency>
    <groupId>ch.qos.logbackgroupId>
    <artifactId>logback-classicartifactId>
    <version>1.0.11version>
dependency>
4.配置logback,  一个简单的logback.xml 文件内容

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%-5level %msg [%logger{16} %d{HH:mm:ss}]%nPattern>
        layout>
    appender>

    <root level="INFO">
        <appender-ref ref="STDOUT" />
    root>
    <logger name="org.apache" level="INFO" />
    <logger name="org.apache.http.wire" level="DEBUG" />
configuration>


你可能感兴趣的:(java)