Skip to content
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

Logging full http request and response? #348

Open
davidfrancisandroidemul opened this issue Jul 6, 2020 · 5 comments
Open

Logging full http request and response? #348

davidfrancisandroidemul opened this issue Jul 6, 2020 · 5 comments
Milestone

Comments

@davidfrancisandroidemul
Copy link

davidfrancisandroidemul commented Jul 6, 2020

Hi,

More of a question than an issue

Can volley show the full http request / response?
I googled and didn't find an answer.

I already have this: VolleyLog.DEBUG = true
and that does show several logging messages, but not the http traffic

If there is no way to do this currently, please could this be raised as an enhancement?

Thanks,

David

@jpd236
Copy link
Collaborator

jpd236 commented Jul 6, 2020

This isn't supported today, but it's a valid feature request to consider. The main snag is that individual Android log messages are limited to ~4K in size, which is often smaller than requests and/or responses. You also have to log data which is potentially binary in nature (e.g. by base64 encoding it), and it can be tricky to try and infer whether the data is binary just from the mimetype.

In the mean time, if you want to do this, my recommendation would be to use a base Request class common to all of your requests which can handle the logging in whatever format you expect. You could also try to do this at the BaseHttpStack level by extending e.g. HurlStack to log the request/response bodies generically.

@jpd236 jpd236 added this to the 1.2.0 milestone Jul 6, 2020
@davidfrancisandroidemul
Copy link
Author

Thanks for considering this!

I am auto generating Volley code using https://github.com/OpenAPITools/openapi-generator
so have limited scope for tweaking the code (although it is possible)

Maybe if there was a simple global "addRequestResponseListener" in Volley, and if set that would receive a callback on every request and response, that would be great. Then it would be up to the implementor of that interface to figure out any complexities wrt log message size etc. A simple impl which just dumps to System.out could possibly be included?

@jpd236
Copy link
Collaborator

jpd236 commented Jul 7, 2020

I'm not familiar with that project, so I don't know what can be tweaked. But if it's not letting you provide a custom RequestQueue and/or Network (which includes the HttpStack), then that's probably a feature request for that project.

@davidfrancisandroidemul
Copy link
Author

davidfrancisandroidemul commented Jul 8, 2020

I don't really want to override all that complex-sounding (!) stuff to do this logging

As a comparison, I am using Micronaut as the backend, and it has a http client which I use in my backend tests

Docs are here for reference: https://docs.micronaut.io/latest/guide/httpClient.html
The docs include:

To debug the requests being sent and received from the HTTP client you can enable tracing logging via your logback.xml file:
logback.xml
<logger name="io.micronaut.http.client" level="TRACE"/>

... so it's just a very quick config change there

@davidfrancisandroidemul
Copy link
Author

Similar results for apache http client
Other frameworks do vary, but at least there is example code on stackoverflow to (allegedly) get the logging to show

@jpd236 jpd236 modified the milestones: 1.2.0, 1.3.0 Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants