aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2006-10-23 22:21:09 +0000
committerJamis Buck <jamis@37signals.com>2006-10-23 22:21:09 +0000
commit9c9443812f1274667cea14edd387c6124205ac1c (patch)
tree9d1820ecd0b19802ff3d049c1ac4d102f83deef8 /activeresource
parent18e2188f5d4453e551fc0ed1e1603205e69e51bb (diff)
downloadrails-9c9443812f1274667cea14edd387c6124205ac1c.tar.gz
rails-9c9443812f1274667cea14edd387c6124205ac1c.tar.bz2
rails-9c9443812f1274667cea14edd387c6124205ac1c.zip
Add basic logging support for logging outgoing requests.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5343 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/CHANGELOG2
-rw-r--r--activeresource/lib/active_resource/base.rb4
-rw-r--r--activeresource/lib/active_resource/connection.rb13
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