mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add basic logging support for logging outgoing requests.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5343 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
18e2188f5d
commit
9c9443812f
3 changed files with 17 additions and 2 deletions
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue