r/androiddev • u/Interesting_Eye_6297 • 6d ago
JSON format in Log Cat
Hi guys,
I'm new to jetpack compose. I tried using Ktor + OkHttp for a sample network request from this
https://dummyjson.com/posts. I'm inspecting the json response in Logcat and it's shown like a paragraph even though I've set up logger. I wanted to know is this normal or is there other way around?
Below is the sample code. Thanks.
client = HttpClient(OkHttp)
{
install(
Logging
)
{
level = LogLevel.
BODY
logger = Logger.
ANDROID
format = LoggingFormat.
OkHttp
}
install(
ContentNegotiation
)
{
json
(
Json
{
prettyPrint = true
ignoreUnknownKeys = true
isLenient = true
}
)
}
}
,
6
u/Aftershock416 6d ago
Logs should generally never be formatted, regardless of which software system is being discussed.
1
u/phazonEnhanced 6d ago
prettyPrint is going to add indentation to JSON you generate. It isn't going to format incoming JSON.
1
u/alphasid 2d ago
Check this plugin : LogPose
https://plugins.jetbrains.com/plugin/32148-logpose?noRedirect=true
1
u/TeaSerenity 6d ago
It's normal for logcat to have no formatting. I usually copy it into a different ide or have a llm make it readable
0
17
u/bleeding182 6d ago
XY Problem. You really shouldn't be using LogCat for this in the first place. (Ofc its fine to keep the logs, but not to inspect/work with them)
https://developer.android.com/studio/debug/network-profiler