android - How do I see all the json response body in Logcat with Ktor? - Stack Overflow

I have a problem using the Ktor HttpClient library because I can't see all the body content that i

I have a problem using the Ktor HttpClient library because I can't see all the body content that is being truncated, but I can see them in OkHttp client library through HttpLoggingInterceptor. I am making a simple get request to this URL: /$param/repos (param must be GitHub user name. burakggs)

Solution: I found a answer in MariusVolkhart's answer from How to log requests in ktor http client?. I changed my configuration and replaced engine to OkHttp. But I think if I decided to use different engines for KMM I would run into same truncated json response body problem.

@Provides
@Singleton
fun provideHttpClient(): HttpClient {
    return HttpClient(OkHttp) {
        engine {
            val loggingInterceptor = HttpLoggingInterceptor()
            loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
            addInterceptor(loggingInterceptor)
            config {

            }
        }

    }
}

I have a problem using the Ktor HttpClient library because I can't see all the body content that is being truncated, but I can see them in OkHttp client library through HttpLoggingInterceptor. I am making a simple get request to this URL: https://api.github/users/$param/repos (param must be GitHub user name. burakggs)

Solution: I found a answer in MariusVolkhart's answer from How to log requests in ktor http client?. I changed my configuration and replaced engine to OkHttp. But I think if I decided to use different engines for KMM I would run into same truncated json response body problem.

@Provides
@Singleton
fun provideHttpClient(): HttpClient {
    return HttpClient(OkHttp) {
        engine {
            val loggingInterceptor = HttpLoggingInterceptor()
            loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
            addInterceptor(loggingInterceptor)
            config {

            }
        }

    }
}
Share Improve this question edited Mar 11 at 7:29 brkggs asked Mar 10 at 13:05 brkggsbrkggs 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

This is a bug in the default implementation of the Logging plugin. As a workaround, you can use the OkHttp logging format:

install(Logging) {
    format = LoggingFormat.OkHttp
    logger = AndroidLogger("ktor-logger")
    level = LogLevel.BODY
}

UPD: The problem with truncation is caused by the Logcat itself which has a limit for a message size for both binary and non-binary logs of ~4076 bytes. See this answer for more information.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744845503a4596810.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信