Document HttpLoggingInterceptor buffers content
See original GitHub issueWe should document (further) that the logging interceptor is not general purpose and fully buffers bodies.
Additionally, consider aggregating a single string for a request and a single string for each response to call the logger with to prevent interleaving on the console/logcat/wherever.
old issue below:
Hi,
I’m working on an android app which downloads books.
some of the books are really large and HttpLoggingInterceptor
tries to log them and therefore I’m getting OutOfMemoryError
which looks like this:
09-17 15:57:02.095 15408-15672/com.some.example E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.some.example, PID: 15408
java.lang.OutOfMemoryError: Failed to allocate a 122708494 byte allocation with 16777216 free bytes and 93MB until OOM
at java.lang.StringFactory.newStringFromBytes(StringFactory.java:79)
at java.lang.StringFactory.newStringFromBytes(StringFactory.java:207)
at okio.Buffer.readString(Buffer.java:631)
at okio.Buffer.readString(Buffer.java:614)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:273)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
in production im not logging the body which fixes the error, but in development i want to be able to log it, how do you suggest me to tackle this issue? thanks.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:21 (9 by maintainers)
Top Results From Across the Web
okhttp-logging-interceptor/src/main/java/com/squareup/okhttp ...
Buffer ;. import okio.BufferedSource;. /**. * An OkHttp interceptor which logs request and response information. Can be applied as an.
Read more >How to log request and response body with Retrofit-Android?
Add the following line to your gradle imports within your build.gradle file to fetch the logging interceptor dependency.
Read more >Example usage for com.squareup.okhttp RequestBody writeTo
Document. Writes the content of this request to out . ... HttpLoggingInterceptor.java ... writeTo(buffer); Charset charset = UTF8; MediaType contentType ...
Read more >okio.Buffer.clone java code examples - Tabnine
@Override public Source source(File file) throws FileNotFoundException { Buffer ... Buffer buffer = source.buffer(); //获取content的压缩类型 String encoding ...
Read more >okhttp3.logging.HttpLoggingInterceptor Maven / Gradle / Ivy
HttpLoggingInterceptor maven / gradle build tool code. ... Show all versions of logging-interceptor Show documentation ... Buffer; import okio.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also – we don’t buffer the content ’cause we’re lazy and don’t know how to do streaming. We buffer it because we think that when a developer is viewing logs they don’t want the bodies of multiple responses to be interleaved. I know you don’t care about that, but that makes you special! And that’s why we have this interceptors API so you can do what you like.
And finally, it’s annoying to open source contributors when you threaten to take your business elsewhere. We’re not trying to build a library that meets everyone’s needs (because we think that would be big and complicated). Instead we’re trying to build a small but extensible library that meets most people’s needs. Whenever somebody says “add my feature or I’m leaving” it isn’t endearing.