diff options
author | José Valim <jose.valim@gmail.com> | 2010-06-24 13:23:43 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-24 13:23:43 +0200 |
commit | 6788db824ab732b13493a9d702dd8fb89fa153c8 (patch) | |
tree | ad9314fdd10b55ebb035959a71be0de921cb0d02 /activeresource/lib | |
parent | 5441e082f9478ddb3c676c681b09786f1391483c (diff) | |
download | rails-6788db824ab732b13493a9d702dd8fb89fa153c8.tar.gz rails-6788db824ab732b13493a9d702dd8fb89fa153c8.tar.bz2 rails-6788db824ab732b13493a9d702dd8fb89fa153c8.zip |
Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing frameworks like ActiveRecord and ActiveResource to log outsude Rails::Application [#4816 state:resolved]
Diffstat (limited to 'activeresource/lib')
4 files changed, 16 insertions, 18 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 521e2b6f5d..6c494a8bcc 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -17,6 +17,7 @@ require 'active_resource/exceptions' require 'active_resource/connection' require 'active_resource/formats' require 'active_resource/schema' +require 'active_resource/log_subscriber' module ActiveResource # ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application. diff --git a/activeresource/lib/active_resource/log_subscriber.rb b/activeresource/lib/active_resource/log_subscriber.rb new file mode 100644 index 0000000000..9e52baf36d --- /dev/null +++ b/activeresource/lib/active_resource/log_subscriber.rb @@ -0,0 +1,15 @@ +module ActiveResource + class LogSubscriber < ActiveSupport::LogSubscriber + def request(event) + result = event.payload[:result] + info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}" + info "--> %d %s %d (%.1fms)" % [result.code, result.message, result.body.to_s.length, event.duration] + end + + def logger + ActiveResource::Base.logger + end + end +end + +ActiveResource::LogSubscriber.attach_to :active_resource
\ No newline at end of file diff --git a/activeresource/lib/active_resource/railtie.rb b/activeresource/lib/active_resource/railtie.rb index aa878c7212..60f6f88311 100644 --- a/activeresource/lib/active_resource/railtie.rb +++ b/activeresource/lib/active_resource/railtie.rb @@ -5,9 +5,6 @@ module ActiveResource class Railtie < Rails::Railtie config.active_resource = ActiveSupport::OrderedOptions.new - require "active_resource/railties/log_subscriber" - log_subscriber :active_resource, ActiveResource::Railties::LogSubscriber.new - initializer "active_resource.set_configs" do |app| app.config.active_resource.each do |k,v| ActiveResource::Base.send "#{k}=", v diff --git a/activeresource/lib/active_resource/railties/log_subscriber.rb b/activeresource/lib/active_resource/railties/log_subscriber.rb deleted file mode 100644 index 86806a93d0..0000000000 --- a/activeresource/lib/active_resource/railties/log_subscriber.rb +++ /dev/null @@ -1,15 +0,0 @@ -module ActiveResource - module Railties - class LogSubscriber < Rails::LogSubscriber - def request(event) - result = event.payload[:result] - info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}" - info "--> %d %s %d (%.1fms)" % [result.code, result.message, result.body.to_s.length, event.duration] - end - - def logger - ActiveResource::Base.logger - end - end - end -end
\ No newline at end of file |