Silence Debug Register in HTTPComponents

How to disable debug logging in http componentenets?

09:23:22.145 [main] DEBUG oahcprotocol.RequestAddCookies - CookieSpec selected: default 09:23:22.145 [main] DEBUG oahcprotocol.RequestAuthCache - Auth cache not set in the context 09:23:22.145 [main] DEBUG oahicPoolingHttpClientConnectionManager - 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 oahicPoolingHttpClientConnectionManager - 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 oahimpl.execchain.MainClientExec - Executing request POST /evt/detect HTTP/1.1 09:23:22.145 [main] DEBUG oahimpl.execchain.MainClientExec - Target auth state: UNCHALLENGED 09:23:22.145 [main] DEBUG oahimpl.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 tried the 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 is 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 not one of them worked. Help is appreciated, thanks!

+6
source share
2 answers

You can specify the correct possible reasons, since the other log4j configuration file is in the class path and overrides your configuration. Therefore, I recommend it. - Make sure the log4j.properties file is in the classpath. Use the command below to view open files by process (provided unix)

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

    jar -tvf a.jar | grep log4j

+1
source

Programmatically, it can be disabled using:

(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); 
0
source

All Articles