studio org not libreria including importar exist example does clase android apache-commons-httpclient

org - libreria httpclient android studio



Cómo habilitar el registro de apache commons HttpClient en Android (4)

Aquí hay una solución (sin profundizar en los detalles)

Consola:

adb shell setprop log.tag.httpclient.wire.header VERBOSE adb shell setprop log.tag.httpclient.wire.content VERBOSE

Código:

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);

Prueba:

java.util.logging.Logger.getLogger("httpclient.wire.content").log(java.util.logging.Level.CONFIG, "hola");

Para habilitar el registro de Apache commons HttpClient en la aplicación Java normal que utilicé:

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");

Pero en Android no veo registros en LogCat.

¿Me estoy perdiendo de algo?


El diablo está en los detalles. Estoy ejecutando el emulador 2.3.3 y lo tengo trabajando con:

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);

y en el shell adb

# setprop log.tag.org.apache.http.wire VERBOSE # setprop log.tag.org.apache.http.headers VERBOSE

Por lo tanto, parece que los especificadores de registro son diferentes.


Ignora mi comentario anterior Encontré la solución en la página de registro de org.apache.http. Su respuesta original se refería al registro httpclient-3.x , y el código de trabajo para las versiones recientes proviene del registro de componentes http.

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");

y propiedades:

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

La diferencia está en los nombres de las etiquetas de registro.


Solo necesitas usar

java.util.logging.Logger.getLogger(yourFullClassName).setLevel(java.util.logging.Level.All);

y

adb shell setprop log.tag.correspondingTag VERBOSE

Android usa esta función para obtener la etiqueta correspondiente del nombre completo de la clase:

public static String loggerNameToTag(String loggerName) { if (loggerName == null) { return "null"; } int length = loggerName.length(); if (length <= 23) { return loggerName; } int lastPeriod = loggerName.lastIndexOf("."); return length - (lastPeriod + 1) <= 23 ? loggerName.substring(lastPeriod + 1) : loggerName.substring(loggerName.length() - 23); }

así que, por ejemplo, quiero habilitar el registro para la clase "org.apache.http.impl.client.DefaultRequestDirector", haga lo siguiente a continuación:

String clzName = "org.apache.http.impl.client.DefaultRequestDirector"; String newClzName = loggerNameToTag(clzName); System.out.println("className:" + clzName + " tagName is " + newClzName); //get tagName from class full name,and then it will be used in setprop Logger jdkLogger = Logger.getLogger(clzName); jdkLogger.setLevel(Level.ALL); if (jdkLogger.isLoggable(Level.FINE)) { jdkLogger.log(Level.FINE, "jdk log msg"); jdkLogger.log(Level.Fine,"tagName is") }

Y luego en adb shell

setprop log.tag.DefaultRequestDirector VERBOSE