diff options
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/CHANGELOG | 2 | ||||
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 4 | ||||
-rw-r--r-- | activeresource/lib/active_resource/connection.rb | 13 |
3 files changed, 17 insertions, 2 deletions
diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG index def1fd8ad4..43ab43c6cb 100644 --- a/activeresource/CHANGELOG +++ b/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] diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 40fd965487..05013e8edd 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -2,6 +2,10 @@ require 'active_resource/connection' module ActiveResource class Base + # The logger for logging diagnostic and trace information during ARes + # calls. + cattr_accessor :logger + class << self attr_reader :site diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 57471957e2..1a1b376d3a 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -2,6 +2,7 @@ require 'net/https' require 'date' require 'time' require 'uri' +require 'benchmark' module ActiveResource class ConnectionError < StandardError @@ -63,8 +64,12 @@ module ActiveResource 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 @@ module ActiveResource 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 |