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
log request bodies in logger middleware #277
Conversation
See my comment in #254. I'm in favor of optional logging of body, but not by default. Maybe introduce an options hash? Also, when you add a new feature, changing old tests is not desireable. Adding new tests is the way to go. |
I can absolutely add an options hash and will modify as you've proposed - fully agree that it makes sense to be optional. I will also restore the tests. Do you have any thoughts on logging response bodies? That could be helpful when ParseXml/Json,etc middleware are used to transform the body. |
If the body is a string, just dump the string. If it was a Hash/Array (e.g. parsed by ParseXml/Json middleware) the logger middleware could dump that data in a prettified version, a la |
I just added an options hash which can accept a boolean to log both request and response bodies: Faraday.new do |b|
b.response :logger, ::Logger.new(STDOUT), :bodies => true
end Or a hash to be more fine-grained: Faraday.new do |b|
b.response :logger, ::Logger.new(STDOUT), :bodies => { :request => true, :response => false }
end |
This is looking mighty good to me, would love to have this possibility by default! |
+1 very useful for debugging |
@mislav is there anything else you'd like to see added here? I didn't squash the commits so that you could see that I reverted the one that I changed in the first commit, happy to do so if that is holding this up. |
+1 Very useful |
This all looks good, but I'm not a huge fan of the { :request_body => true,
:response_body => false
} But that makes turning both options on is awkward. So I guess the current syntax can stay. Tips:
Sorry for making you do so much work. Your contribution is appreciated! ;) |
Oh, and to get rid of Travis failures, rebase your work to master and force push to your branch again. You can squash your commits or you don't have to (it's easy do to from my end as well). I've fixed most of the failures, with the exception of an occasional glitch due to test WEBrick server choking on the volume of the requests. |
@mislav no worries. I made changes based on your suggestions and rebased against master. I decided that the |
In terms of the options syntax, what are your thoughts on supporting both options: { :bodies => false } # log neither
{ :bodies => true } # log both
{ :request_body => true, :response_body => false } # mixed use That avoids the nested hash. |
+1 |
+1, please merge this change. Very useful and saved me when debugging API request errors with Google API Client. |
How about instead of just passing true/false we could also specify an array of response types that should be logged ? Something like this: Also, I'm not so sure about using pretty_print here. After all, if you require such verbose logging, chances are you will want to log the request verbatim. |
@mislav any plans to merge this ? |
Yep, I still think it's useful to merge this. I haven't changed my opinion. However, I haven't gotten around to merging it yet. Are you impatient? Are you not able to easily copy the class from this pull request and vendor and use it in your project? For me, merging is not just a matter of hitting the Merge Button™. I have to do a final review of the code, review the quality of tests, decide which Faraday branches does the feature belong to, does it keep backwards compatibility, add missing documentation for new features, etc. |
I want to use this in production, so I preffer to wait until this is properly tested, reviewed etc. I don't want to be pushy in any way, was just curious if you plan to merge it soon, or if I should clone and merge myself. |
+1 |
@spagalloco Thanks for this 👍 |
+1 Is there anything I can do to help get this into master? Logging of post bodies is extremely helpful for debugging calls I'm making to RESTful services. |
would love to see this merged. 👍 |
+1, very much desired for simpler debugging. |
Looking forward to this merge |
+1 |
I can understand why one would delay merging a pull request in order to properly document and test it for a release as @mislav pointed out. For those who would like to use this feature quickly, and not mess with merging pull requests within gems, I just created my own Middleware that borrows code from this pull request: https://gist.github.com/vasanthela/7afb8916c662ba783041 It can be used in the meantime for those with immediate need for this feature, like myself. |
Thanx @vasanthela. |
Why isnt nobody merging this? |
log request bodies in logger middleware
Reviewed an merged. |
Wow. That was fast 💃 |
👍 |
Cheers! 🍻 |
Woohoo! |
I've found it helpful to see the request body in addition to request headers when using the logging middleware. This change adds logging for the body.
While adding tests, I noticed some failures in
env_test
which I didn't address in this PR. Are you aware of these failures?