0

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

randy
  • 1,685
  • 3
  • 34
  • 74
  • Your provided log doesn't match with either pattern found in config file. Can you give proper log? Or, proper config file? – sazzad Sep 17 '17 at 05:39
  • hello sazzad, one thing i forgot to put in the example was my app (ntapp and i have added it to the example). this log4j2.xml is in the classpath and i know the app is using it correctly because of what i get in the console. i also get in the console when i run the app, the messages as shown in the description from http and that is what i am trying to get rid of thanks – randy Sep 17 '17 at 07:12
  • well, **IF** the log you provided is exactly what you're getting, then it is not done through log4j2 (as the patterns don't match). So, I don't think you would be able to suppress by log4j2. – sazzad Sep 17 '17 at 07:28

1 Answers1

1

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 )

randy
  • 1,685
  • 3
  • 34
  • 74