How to disable log4j logging in Http Client 4.1 to log into FileAppender

Here is my log4j configuration for the HTTP client:

log4j.appender.HTTPCLIENT_APPDR=com.xxx.log.FileAppender log4j.appender.HTTPCLIENT_APPDR.File=${user.dir}/log/access.log log4j.appender.HTTPCLIENT_APPDR.layout=org.apache.log4j.PatternLayout log4j.appender.HTTPCLIENT_APPDR_APPDR.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss SSS}ms %-5p [%t] - %m%n log4j.appender.HTTPCLIENT_APPDR.MaxFileSize=20000KB log4j.appender.HTTPCLIENT_APPDR.MaxBackupIndex=30 log4j.logger.org.apache.http=DEBUG,HTTPCLIENT_APPDR 

I would like it to disable httpclient from CODE depending on the environment I was in (I know how to disable it from log4j.properties).

I tried to insert these lines:

 + System.setProperty("log4j.logger.org.apache.http", "ERROR"); 

or

 + Logger.getLogger("log4j.logger.org.apache.http").setLevel(Level.off) 

at the beginning of my application, but it does not work.

  1. Can I access the log4j properties from the System class?
  2. When I look at the Logger.getLogger("log4j.logger.org.apache.http") Is the level zero? If it's not DEBUG?

What worked finally

  Logger.getLogger ("org.apache.http"). SetLevel (org.apache.log4j.Level.OFF);

I did not use the correct key.

Yours faithfully,

+4
source share
2 answers

What worked finally was Logger.getLogger ("org.apache.http") setLevel (org.apache.log4j.Level.OFF). I did not use the correct key.

+5
source

If you have a log4j.properties file, add this line

log4j.logger.org.apache.http=WARN

This is checked only in Apache HttpClient 4

+3
source

Source: https://habr.com/ru/post/1440305/


All Articles