Skip to content

Instantly share code, notes, and snippets.

@iNecas
Last active October 19, 2018 15:15
Show Gist options
  • Save iNecas/3b7af8ef26f7ae0de9c1591a77361c6a to your computer and use it in GitHub Desktop.
Save iNecas/3b7af8ef26f7ae0de9c1591a77361c6a to your computer and use it in GitHub Desktop.
RestClient 2.0 patch for more readable debug logging
commit 13c25907e7c750eb1f4e19508e6e7aa528dd2f3a
Author: root <[email protected]>
Date: Fri Oct 19 16:47:55 2018 +0200
add more logging
diff --git a/lib/restclient.rb b/lib/restclient.rb
index bdb53f0..588318b 100644
--- a/lib/restclient.rb
+++ b/lib/restclient.rb
@@ -155,7 +155,9 @@ module RestClient
end
end
- @@env_log = create_log ENV['RESTCLIENT_LOG']
+ puts "====== log: #{ ENV['RESTCLIENT_LOG'] }"
+ #@@env_log = create_log ENV['RESTCLIENT_LOG']
+ @@env_log = create_log "/var/log/foreman/ovirt.log"
@@log = nil
diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb
index e818aad..21b8b75 100644
--- a/lib/restclient/request.rb
+++ b/lib/restclient/request.rb
@@ -582,7 +582,7 @@ module RestClient
out = []
out << "RestClient.#{method} #{redacted_url.inspect}"
- out << payload.short_inspect if payload
+ out << payload.to_s_inspect if payload
out << processed_headers.to_a.sort.map { |(k, v)| [k.inspect, v.inspect].join("=>") }.join(", ")
RestClient.log << out.join(', ') + "\n"
end
@@ -595,8 +595,9 @@ module RestClient
else
res.body.nil? ? 0 : res.body.size
end
+ decoded_body = Request.decode(res['content-encoding'], res.body) if res.body
- RestClient.log << "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{size} bytes\n"
+ RestClient.log << "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{decoded_body.inspect} #{size} bytes\n"
end
# Return a hash of headers whose keys are capitalized strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment