David Williams
David Williams

Reputation: 8664

Silence Debug Logging in HTTPComponents

How do I silence the debug logging in http componenets?

09:23:22.145 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
09:23:22.145 [main] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
09:23:22.145 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://example.org:80][total kept alive: 1; route allocated: 1 of 100; total allocated: 1 of 200]
09:23:22.145 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://diagnostics-uat.corp.apple.com:80][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 200]
09:23:22.145 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request POST /evt/detect HTTP/1.1
09:23:22.145 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
09:23:22.145 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
09:23:22.145 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /evt/detect HTTP/1.1
09:23:22.145 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 92

I have tried a code based solution:

static {
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "warn");
}

public static void main(String[] args) throws Exception {

And this log4j.properties

log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n

log4j.logger.org.apache.http=WARN
log4j.logger.org.apache.http.wire=WARN

But neither have worked. Help is appreciated, thanks!

Upvotes: 7

Views: 2923

Answers (2)

Hartmut Pfarr
Hartmut Pfarr

Reputation: 6139

Programmatically, it can be set silent with:

(Apache HttpComponents 4.3.5)

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

...

Logger.getLogger("org.apache.http")        .setLevel(Level.WARN);
Logger.getLogger("org.apache.http.wire")   .setLevel(Level.WARN);
Logger.getLogger("org.apache.http.headers").setLevel(Level.WARN);

Upvotes: 0

software.wikipedia
software.wikipedia

Reputation: 719

You settings are correct possible causes may be another log4j config file is in the classpath and overriding your config. So I will recommended this. - Ensure you log4j.properties file is in classpath . Use below command to see open files by a process (assuming unix)

lsof -p java-process-pid | grep log4j
  • Search for log4j.properties in your runtime folders and get rid of all duplicate files (if possible) - otherwise change them all.
  • Search for log4j.xml and do the same.
  • Sometimes I have seen third party jars that ship with a log4j.xml or log4j.properties so in worst case check for all jars using below command

    jar -tvf a.jar | grep log4j

Upvotes: 2

Related Questions