Skip to content

Commit

Permalink
add pretty logging when SWIRL_LOG is set
Browse files Browse the repository at this point in the history
  • Loading branch information
bmizerany committed Mar 2, 2011
1 parent 8073678 commit a845487
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/swirl/aws.rb
Expand Up @@ -108,6 +108,9 @@ def call(action, query={}, &blk)
end

def call!(action, query={}, &blk)
log "Action: #{action}"
log "Query: #{query.inspect}"

# Hard coding this here until otherwise needed
method = "POST"

Expand All @@ -122,9 +125,8 @@ def call!(action, query={}, &blk)
body += "&" + ["Signature", compile_signature(method, body)].join("=")

post(body) do |code, xml|
if ENV["SWIRL_LOG"]
puts response.body
end
log "HTTP Response Code: #{code}"
log xml.gsub("\n", "\n[swirl] ")

data = Crack::XML.parse(xml)
blk.call(code, data)
Expand All @@ -149,6 +151,12 @@ def inspect
"<#{self.class.name} version: #{@version} url: #{@url} aws_access_key_id: #{@aws_access_key_id}>"
end

def log(msg)
if ENV["SWIRL_LOG"]
$stderr.puts "[swirl] #{msg}"
end
end

end

end

0 comments on commit a845487

Please sign in to comment.