问题描述
这是我的HTTP客户端的Log4J配置:
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
我希望它根据我所处的环境关闭httpclient记录(我知道如何从log4j.properties禁用它).
我尝试插入以下行:
+ System.setProperty("log4j.logger.org.apache.http", "ERROR");
或
+ Logger.getLogger("log4j.logger.org.apache.http").setLevel(Level.off)
在我的应用程序的开头,但它不起作用.
- Can I access the log4j properties from the System class?
- When I look at the Logger.getLogger("log4j.logger.org.apache.http")级别为null?应该不应该调试吗?
最终有效的是
Logger.getLogger("org.apache.http").setLevel(org.apache.log4j.Level.OFF);
我没有使用正确的键.
问候,
推荐答案
最终有效的是 logger.getLogger(" org.apache.http").setLevel(org.apache.log4j.level.off); 我没有使用正确的键.
其他推荐答案
如果您有log4j.properties文件,请添加此行
log4j.logger.org.apache.http=WARN
这仅在Apache HttpClient 4
中测试问题描述
Here is my log4j configuration for a 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 turn off the httpclient logging from the CODE depending on the environment I am in (I know how to disable it from the log4j.properties).
I tried inserting these lines:
+ System.setProperty("log4j.logger.org.apache.http", "ERROR");
or
+ Logger.getLogger("log4j.logger.org.apache.http").setLevel(Level.off)
in the start of my application but it does not work.
- Can I access the log4j properties from the System class?
- When I look at the Logger.getLogger("log4j.logger.org.apache.http") the level is null? Should it not be DEBUG?
What worked finally,
Logger.getLogger("org.apache.http").setLevel(org.apache.log4j.Level.OFF);
I was not using the right key.
Regards,
推荐答案
What worked finally, Logger.getLogger("org.apache.http").setLevel(org.apache.log4j.Level.OFF); I was not using the right key.
其他推荐答案
If you have a log4j.properties file, add this line
log4j.logger.org.apache.http=WARN
This is only tested in Apache HttpClient 4