美文网首页
解决httpClient在控制台打印Debug日志

解决httpClient在控制台打印Debug日志

作者: 小杜v587 | 来源:发表于2021-03-14 20:04 被阅读0次

    解决httpClient在控制台打印Debug日志

    问题:httpclient在运行或者调试中会在控制台一直打印日志如下代码:

    21:57:41.413 [main] DEBUG org.apache.http.wire - << "                                   [\r][\n]"
    21:57:41.413 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
    21:57:41.413 [main] DEBUG org.apache.http.wire - << "                                   [\r][\n]"
    21:57:41.413 [main] DEBUG org.apache.http.wire - << "                               </ul>[\n]"
    21:57:41.413 [main] DEBUG org.apache.http.wire - << "    [\n]"
    21:57:41.424 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.425 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
    21:57:41.425 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
    21:57:41.425 [main] DEBUG org.apache.http.wire - << "                   </div>[\r][\n]"
    21:57:41.425 [main] DEBUG org.apache.http.wire - << "                </li>[\r][\n]"
    21:57:41.425 [main] DEBUG org.apache.http.wire - << "            [\r][\n]"
    21:57:41.425 [main] DEBUG org.apache.http.wire - << "            [\r][\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "        </ul>[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.433 [main] DEBUG org.apache.http.wire - << "<div class="details">[\n]"
    21:57:41.442 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.443 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.443 [main] DEBUG org.apache.http.wire - << "<div class="details-body details-precis  ">[\n]
    "
    21:57:41.443 [main] DEBUG org.apache.http.wire - << "<div class="details-state">[\n]"
    21:57:41.443 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.443 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
    21:57:41.443 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
    21:57:41.443 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.455 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
    21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
    21:57:41.455 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
    21:57:41.455 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
    21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
    

    第一种情况:创建logback.xml

    <configuration>
        <logger name="org.apache" level="WARN" />
        <logger name="httpclient" level="WARN" />
    </configuration>
    

    第二种情况:如果用了log4j2。在log4j2.xml加入下面的代码。

        <!--解决HttpClient打印无用代码-->
        <Logger name="org.apache.hc.client5.http" level="ERROR">
            <AppenderRef ref="ConsoleAppender"/>
        </Logger>
        <Logger name="org.apache.http" level="ERROR">
            <AppenderRef ref="ConsoleAppender"/>
        </Logger>
        <Root level="DEBUG">
            <AppenderRef ref="ConsoleAppender"/>
        </Root>
    </Loggers>
    

    三:如果引入了Report Portal,在log4j2.xml加入以下代码

        <!--解决HttpClient打印无用代码-->
        <Logger name="org.apache.hc.client5.http" level="ERROR">
            <AppenderRef ref="ConsoleAppender"/>
            <AppenderRef ref="ReportPortalAppender"/>
        </Logger>
        <Logger name="org.apache.http" level="ERROR">
            <AppenderRef ref="ConsoleAppender"/>
            <AppenderRef ref="ReportPortalAppender"/>
        </Logger>
        <Logger name="rp.org.apache.http" level="ERROR">
            <AppenderRef ref="ConsoleAppender"/>
            <AppenderRef ref="ReportPortalAppender"/>
        </Logger>
        <Root level="DEBUG">
            <AppenderRef ref="ConsoleAppender"/>
            <AppenderRef ref="ReportPortalAppender"/>
        </Root>
    </Loggers>
    

    相关文章

      网友评论

          本文标题:解决httpClient在控制台打印Debug日志

          本文链接:https://www.haomeiwen.com/subject/grrccltx.html