-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document HttpLoggingInterceptor buffers content #4273
Comments
You want to print a 120 MB string to logcat? Good luck reading that. The error happens here: okhttp/okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.java Line 273 in de4acc5
Currently logger prints the whole body, which in your case is over 100 MB of data. Perhaps you could copy okhttp/okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.java Line 241 in de4acc5
Or print it in chunks, which I leave to you as an excercise (i.e. I don't know how to do that off the top of my head). |
I'm seeing this too when I'm downloading very large datasets. the logging intercepter should never ever ever cause an OOM. Here's my stack trace:
|
No way is the clients issue, this ticket should not be closed until fixed. |
The logging interceptor will never cause an OOM when you are not logging ridiculously large bodies. |
Actually that's a lie. If you have 1 byte free in your heap and you ask the logging interceptor to log a 2-byte body it will cause an OOM. But you asked it. So it tried. |
Dude, thats a terrible excuse. |
I appreciate the work done on this library, but since I, and millions of others depend on it, I'm also not willing to just accept that. |
Why are you logging bodies when streaming gigs of data? Also, as documented, this logger buffers bodies and prevents streaming. It's not a general-purpose logger meant to solve all needs. It's meant to be simple. If you need logging off gigs of streaming bodies you need a custom logger. |
Thanks the logger for the library, and sometimes you need to do both at
once.
A custom logger might be a solution for being able to control the things
more closely, but under no situation, is it cool for the logger of a
library to generate an OOM error.
…On Fri., Oct. 19, 2018, 16:12 Jake Wharton, ***@***.***> wrote:
Why are you logging bodies when streaming gigs of data? Also, as
documented, this logger buffers bodies and prevents streaming. It's not a
general-purpose logger meant to solve all needs. It's meant to be simple.
If you need logging off gigs of streaming bodies you need a custom logger.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4273 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADuRWeXUpey3jGCPJLGadFIpTkW2z3dpks5umjJEgaJpZM4Wr5Yg>
.
|
As I've already stated, that is an impossible thing to accomplish. Every
call to 'new' everywhere in your application (including inside libraries
and the JDK) is always susceptible to OOM no matter what you do.
Or, put another way, this logger will never OOM provided you've allocated
enough heap for it to log the response body sizes that you've requested.
On Mon, Oct 22, 2018 at 8:47 PM Brill Pappin <notifications@github.com>
wrote:
… Thanks the logger for the library, and sometimes you need to do both at
once.
A custom logger might be a solution for being able to control the things
more closely, but under no situation, is it cool for the logger of a
library to generate an OOM error.
On Fri., Oct. 19, 2018, 16:12 Jake Wharton, ***@***.***>
wrote:
> Why are you logging bodies when streaming gigs of data? Also, as
> documented, this logger buffers bodies and prevents streaming. It's not a
> general-purpose logger meant to solve all needs. It's meant to be simple.
> If you need logging off gigs of streaming bodies you need a custom
logger.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#4273 (comment)>,
or mute
> the thread
> <
https://github.com/notifications/unsubscribe-auth/ADuRWeXUpey3jGCPJLGadFIpTkW2z3dpks5umjJEgaJpZM4Wr5Yg
>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4273 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEcNqg_Vdm2ODp5NB0wMZ9sxlXfnNks5unmcHgaJpZM4Wr5Yg>
.
|
Assume a programmer knows how it works. |
I clearly can't assume that from this thread. I'll re-purpose it for better documentation on the logger about the fact that it's not general purpose and that it buffers all content. In fact, we probably shouldn't be calling the logger multiple times for each request and response but instead create a single string for a request and a string string for a response to prevent interleaving. |
It's clearly a low priority for the okhttp team, but logging is one of the fundamental tools that all your developer users need. If I can't trust it not to toss out a random OOM, when a request turned out to be larger than expected, then I might as well switch to another library. |
I think we’re talking past each other. Our expectation of BODY logging is that it’s something you’d use during development only, so you can confirm what you’re sending and receiving match your expectations. If you’re using BODY logging in a situation where you’re logging more than a developer would plausibly read, or if you’re using it in an environment where an OOM would impact an end-user, you’re using it beyond our expected use case. I don’t think we want to build a BODY logger for the “arbitrarily large” bodies you speak of, not because we don’t value your use case, but because it’s difficult to do in a way that suits everyone. Instead, we provide guidance on the OkHttp wiki on how to write your own interceptors that do whatever you want. If you don’t like our logging interceptor who cares? The whole point of interceptors is that you can write your own. |
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. |
|
It wouldn't be hard, but we're not interested in providing these features. Sounds like you should write your own interceptor as the documentation recommends. |
Closing out as we actively advise forking HttpLoggingInterceptor, and not actively working on this. What is being asked for is completely reasonable, but we are not going to implement as part of the core library. If there is a better open source library providing an improved HttpLoggingInterceptor, we should just link to that. |
2 years later, same issue, as a developer I understand what everyone is saying... but throwing an error because you are printing something and now you ran of space to print it it is a bug, if you ran out of space add a catch on it, and print the error silently dont kill the app because someone uses the library for doing normal requests and requires to upload a 20 mb image of video that it is parsed on BASE64... I mean it is not a bug on developers code it is a bug on your code. Killing the thread dont kill the bug, I have been using the library for some years now and I know this is a KNOWN BUG... |
@r9software are you doing body logging in development or elsewhere? |
@r9software It's an optional module of OkHttp that has limitations with large bodies that has been well known for a long time. The advice has consistently been that if you want something that suits your case better then you should fork the HttpLoggingInterceptor library and adjust it to your needs. If you are disappointed 2 years later you will presumably be twice as disappointed after 4 years. You had and still have two choices
|
We 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 gettingOutOfMemoryError
which looks like this: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.
The text was updated successfully, but these errors were encountered: