如何在Android上启用apache commons HttpClient的日志记录

ale*_*2k8 30 android apache-commons-httpclient

要在我使用的普通Java应用程序中启用apache commons HttpClient的日志记录:

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
Run Code Online (Sandbox Code Playgroud)

但在android上我没有看到LogCat中的日志.

我错过了什么吗?

Joe*_*Joe 61

忽略我之前的评论.我在org.apache.http日志页面上找到了解决方案.您的原始答案是指httpclient-3.x日志记录,最新版本的工作代码来自http-components logging

java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST);
java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST);

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");
Run Code Online (Sandbox Code Playgroud)

和属性:

adb shell setprop log.tag.org.apache.http VERBOSE
adb shell setprop log.tag.org.apache.http.wire VERBOSE
adb shell setprop log.tag.org.apache.http.headers VERBOSE
Run Code Online (Sandbox Code Playgroud)

不同之处在于日志记录标记名称.


ale*_*2k8 8

这是一个解决方案(没有深入细节)

安慰:

adb shell setprop log.tag.httpclient.wire.header VERBOSE
adb shell setprop log.tag.httpclient.wire.content VERBOSE
Run Code Online (Sandbox Code Playgroud)

码:

java.util.logging.Logger.getLogger("httpclient.wire.header").setLevel(java.util.logging.Level.FINEST);
java.util.logging.Logger.getLogger("httpclient.wire.content").setLevel(java.util.logging.Level.FINEST);
Run Code Online (Sandbox Code Playgroud)

测试:

java.util.logging.Logger.getLogger("httpclient.wire.content").log(java.util.logging.Level.CONFIG, "hola");
Run Code Online (Sandbox Code Playgroud)