Created
January 11, 2012 14:59
Revisions
-
henrik created this gist
Jan 11, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ -------------------------------------------------- lib/foo.rb:22:in `save' >> REQUEST: { "CashBook_Book": { "cashBookHandle": { "Number": "14" } } } << RESPONSE: { "CashBook_BookResponse": { "xmlns": "http://e-conomic.com", "CashBook_BookResult": { "Number": "14" } } } -------------------------------------------------- This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ # config/initializers/savon.rb # Don't mention the adapter! HTTPI.log = false # Log pretty JSON instead of XML, and never mind URL and headers. class Savon::SOAP::Request def log_request(url, headers, body) Savon.log "" log_calling_line Savon.log "" Savon.log ">> REQUEST:" log_soap_prettily body end def log_response(code, body) Savon.log "" Savon.log "<< RESPONSE:" log_soap_prettily body Savon.log "" Savon.log "-"*50 end def log_calling_line calling_line = caller[1..-1].find { |line| line.include?(Rails.root.to_s) } calling_line.sub!(Rails.root.to_s + "/", "") Savon.log calling_line end def log_soap_prettily(soap) # depends on json gem hash = Hash.from_xml(soap) body = hash["Envelope"]["Body"] json = JSON.pretty_generate(body) Savon.log json end end