-
-
Save charroch/cf23c4e184228a132390 to your computer and use it in GitHub Desktop.
Enable full httpclient logging using the normal java.util.logger within android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.logging.Handler; | |
import java.util.logging.Level; | |
import java.util.logging.LogManager; | |
import java.util.logging.LogRecord; | |
import java.util.logging.Logger; | |
import android.util.Log; | |
public class DebugLogConfig { | |
static DalvikLogHandler activeHandler; | |
protected static class DalvikLogHandler extends Handler { | |
private static final String LOG_TAG = "HttpClient"; | |
@Override | |
public void close() { | |
// do nothing | |
} | |
@Override | |
public void flush() { | |
// do nothing | |
} | |
@Override | |
public void publish(LogRecord record) { | |
if (record.getLoggerName().startsWith("org.apache")) { | |
Log.d(LOG_TAG, record.getMessage()); | |
} | |
} | |
} | |
public static void enable() { | |
try { | |
String config = "org.apache.http.impl.conn.level = FINEST\n" | |
+ "org.apache.http.impl.client.level = FINEST\n" | |
+ "org.apache.http.client.level = FINEST\n" + "org.apache.http.level = FINEST"; | |
InputStream in = new ByteArrayInputStream(config.getBytes()); | |
LogManager.getLogManager().readConfiguration(in); | |
} catch (IOException e) { | |
Log | |
.w(DebugLogConfig.class.getSimpleName(), | |
"Can't read configuration file for logging"); | |
} | |
Logger rootLogger = LogManager.getLogManager().getLogger(""); | |
activeHandler = new DalvikLogHandler(); | |
activeHandler.setLevel(Level.ALL); | |
rootLogger.addHandler(activeHandler); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
usage: | |
DebugLogConfig.enable(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't
DebugLogConfig
be a static class if the usage isDebugLogConfig.enable()
?