把log4j记录httpclient [英] put log4j logging httpclient

查看:191
本文介绍了把log4j记录httpclient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用log4j登录httpclient. 为此,我添加了一个文件commons-logging.properties,内容为org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger. 然后,我添加了一个文件log4j.properties,其内容由httpclient文档提供了以下内容作为记录示例:

I want to put on logging in httpclient with log4j. Doing this, I added a file commons-logging.properties with the content org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger. Then I added a file log4j.properties with the following content provided by httpclient documentation as a logging example:

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=DEBUG
log4j.logger.org.apache.http.wire=ERROR

两个文件都位于类路径中.我输入了以下参数

Both files reside in the classpath. I put the following parameters

-Dlog4j.configuration=log4j.properties
-Dlog4j.debug

但是,当我运行通过httpclient执行http请求的程序时,看不到任何日志输出.从这个意义上讲,后一个参数应该使log4j的输出变得冗长,因为它显示了一些内容,例如使用的属性文件.根本不显示. 我尽力尝试的是通过

However, when I run my programm which executes http requests with the httpclient I do not see any logging output. The latter parameter should make the output of log4j verbose in that sense, that it displays several things e.g. the used properties files. This is not displayed at all. What I tried as wel is to read out the logger programmaciatally with

Logger.getLogger("log4j.logger.org.apache.http.wire").getLevel().toString()

这将引发空指针异常.

此外,我阅读

LogManager.getCurrentLoggers().hasMoreElements()

这总是错误的.

httpclient似乎没有激活" log4j.有人可以帮我在这里做什么,以便打开日志记录吗?

It seems like log4j is not "activated" for httpclient. Can anyone help me here what I could do in order to turn the logging on?

(是的,我已经在stackoverflow上阅读了相关主题)

(Yes, I already read related topics here at stackoverflow)

非常感谢您

费利克斯

推荐答案

在Android上使用httpclient时,如何打开/关闭WIRE和HEADER记录器存在一些共同冲突,涉及commons日志界面和CW.

there is some kind of wierd conflict involving the commons log interface and the CW on how to active/deactive the WIRE and HEADER loggers when using httpclient on android...

仅涉及一个选择重载/重新实现android记录器的项目,为android上的WIRE和HEADER记录器提供了一个钩子,请检查

concerning just one project that chose to overload/reimplement android logger, providing a hook for the WIRE and HEADER loggers on android, check here

FWIW,如果您在REST接口的android系统中进行大量低级使用,而您只是想快速切换日志记录,我对

FWIW if you are doing lots of low level usage in android of REST interfaces and u just want quick way to toggle logging, I have had luck with his project and i just use 2 versions of a jar , depending on whether i need logging. Each new rev on native, apache core or client, you can run his script to convert apache native for android usage. Its a bit down in the weeds but it will work.

这篇关于把log4j记录httpclient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆