Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add basic logging support for logging outgoing requests.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5343 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 9c9443812f1274667cea14edd387c6124205ac1c 1 parent 18e2188
@jamis jamis authored
View
2  activeresource/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add basic logging support for logging outgoing requests. [Jamis Buck]
+
* Add Base.delete for deleting resources without having to instantiate them first. [Jamis Buck]
* Make #save behavior mimic AR::Base#save (true on success, false on failure). [Jamis Buck]
View
4 activeresource/lib/active_resource/base.rb
@@ -2,6 +2,10 @@
module ActiveResource
class Base
+ # The logger for logging diagnostic and trace information during ARes
+ # calls.
+ cattr_accessor :logger
+
class << self
attr_reader :site
View
13 activeresource/lib/active_resource/connection.rb
@@ -2,6 +2,7 @@
require 'date'
require 'time'
require 'uri'
+require 'benchmark'
module ActiveResource
class ConnectionError < StandardError
@@ -63,8 +64,12 @@ def post(path, body = '')
end
private
- def request(method, *arguments)
- handle_response(http.send(method, *arguments))
+ def request(method, path, *arguments)
+ logger.info "requesting #{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger
+ result = nil
+ time = Benchmark.realtime { result = http.send(method, path, *arguments) }
+ logger.info "--> #{result.code} #{result.message} (#{result.body.length}b %.2fs)" % time if logger
+ handle_response(result)
end
def handle_response(response)
@@ -103,5 +108,9 @@ def build_request_headers
def authorization_header
(@site.user || @site.password ? { 'Authorization' => 'Basic ' + ["#{@site.user}:#{ @site.password}"].pack('m').delete("\r\n") } : {})
end
+
+ def logger
+ ActiveResource::Base.logger
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.