Created
December 20, 2018 13:08
-
-
Save abhinav272/065ef1f669c89284081665f26f0fd8e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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