Skip to content

Instantly share code, notes, and snippets.

@abhinav272
Created December 20, 2018 13:08
Show Gist options
  • Save abhinav272/065ef1f669c89284081665f26f0fd8e7 to your computer and use it in GitHub Desktop.
Save abhinav272/065ef1f669c89284081665f26f0fd8e7 to your computer and use it in GitHub Desktop.
import android.util.Log;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import okhttp3.logging.HttpLoggingInterceptor;
public class CustomHttpLogger implements HttpLoggingInterceptor.Logger {
@Override
public void log(String message) {
final String logName = "OkHttp";
if (!message.startsWith("{")) {
Log.d(logName, message);
return;
}
try {
String prettyPrintJson = new GsonBuilder().setPrettyPrinting().create().toJson(new JsonParser().parse(message));
Log.d(logName, prettyPrintJson);
} catch (JsonSyntaxException m) {
Log.d(logName, message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment