Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Debugging stuff for activeresource
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrall committed Aug 18, 2011
1 parent 43c5e10 commit 09c1a04
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Expand Down
7 changes: 7 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,12 @@

# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin

config.after_initialize do
ActiveResource::Base.logger = Rails.logger
ActiveSupport::Notifications.unsubscribe "request.active_resource"
ActiveResource::VerboseLogSubscriber.attach_to :active_resource
end
end

require 'pp'
19 changes: 19 additions & 0 deletions config/initializers/monkey_patch_active_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module ActiveResource
class Connection
private
# Makes a request to the remote service.
def request(method, path, *arguments)
result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
payload[:method] = method
payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
payload[:request_arguments] = arguments
payload[:result] = http.send(method, path, *arguments)
end
handle_response(result)
rescue Timeout::Error => e
raise TimeoutError.new(e.message)
rescue OpenSSL::SSL::SSLError => e
raise SSLError.new(e.message)
end
end
end
15 changes: 15 additions & 0 deletions lib/active_resource/verbose_log_subscriber.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module ActiveResource
class VerboseLogSubscriber < ActiveSupport::LogSubscriber
def request(event)
result = event.payload[:result]
info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}"
event.payload[:request_arguments].each {|s| debug s }
info "--> %d %s %d (%.1fms)" % [result.code, result.message, result.body.to_s.length, event.duration]
debug result.body.to_s
end

def logger
ActiveResource::Base.logger
end
end
end

0 comments on commit 09c1a04

Please sign in to comment.