Search code examples
javalog4j2apache-commonsapache-commons-httpclientapache-commons-logging

Reduce the logging noise from org.apache.http.client when using log4j2


I am starting a new java app and going to use log4j2 ( i am a newbie to log4j2) My app is logging correctly, but I want to get rid of all the warnings I am getting from org.apache.http

According to https://hc.apache.org/httpcomponents-client-ga/logging.html i should be able to control via log4j(although they only give examples for log4j and not log4j2).

my log file has entries like

Sep 16, 2017 9:01:32 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Invalid cookie header: "Set-Cookie: visid_incap_661002=+HabQKJHRbKzy; expires=Sun, 16 Sep 2018 11:41:58 GMT; path=/; Domain=.mydomain.com". Invalid 'expires' attribute: Sun, 16 Sep 2018 11:41:58 GMT

I am trying to suppress all the WARNINGs from org.apache.http.client Some articles say to the client is actually using org.apache.http.wire , but nothing i have tried seems to work

this is my log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
    <Appenders>
        <RollingFile name="fileLogger" fileName="${basePath}/app-info.log" filePattern="${basePath}/app-info-%d{yyyy-MM-dd}.log">
            <PatternLayout>
                <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" modulate="true" />
            </Policies>
        </RollingFile>

        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout   pattern="[%L][%-5level] %d{yyyy-MM-dd HH:mm:ss} [%t] %c{1} - %msg%n" />
        </Console>
    </Appenders>
    <Loggers>

        <logger name="org.apache.http.client" level="ERROR" />
        <logger name="org.apache.http.wire" level="ERROR" />
        <logger name="org.apache.commons.httpclient" level="ERROR" />
        <logger name="ntapp" level="debug" additivity="true">
           <appender-ref ref="fileLogger" level="INFO" />
        </logger>
        <Root level="INFO" additivity="false">
            <appender-ref ref="console" />
        </Root>

    </Loggers>
</Configuration>

THanks for any help


Solution

  • So this article appears to be the correct way to fix my issue , and it did.

    Stackoverflow article - Solution to my issue

    would still like to understand why i could not do it via the logger ( from the doc of http client it looked like i should be able to )