diff options
author | José Valim <jose.valim@gmail.com> | 2009-12-27 13:32:40 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-12-27 13:32:40 +0100 |
commit | 97db79ab3c0af7b6805dcaee99384d96ccb3567d (patch) | |
tree | dcb8856f92f3167780134f5f7b7c1a720bbc8e20 /actionpack | |
parent | 7e8b7f46bfc086a36db996420fbee93348c5268e (diff) | |
download | rails-97db79ab3c0af7b6805dcaee99384d96ccb3567d.tar.gz rails-97db79ab3c0af7b6805dcaee99384d96ccb3567d.tar.bz2 rails-97db79ab3c0af7b6805dcaee99384d96ccb3567d.zip |
Remove ActiveRecord runtime logging from ActionPack and place in ActiveRecord, adding it through config.action_controller.include hook.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/metal/active_record_runtime.rb | 27 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/logger.rb | 17 | ||||
-rw-r--r-- | actionpack/lib/action_controller/rails.rb | 1 |
3 files changed, 15 insertions, 30 deletions
diff --git a/actionpack/lib/action_controller/metal/active_record_runtime.rb b/actionpack/lib/action_controller/metal/active_record_runtime.rb deleted file mode 100644 index 29f6dcc783..0000000000 --- a/actionpack/lib/action_controller/metal/active_record_runtime.rb +++ /dev/null @@ -1,27 +0,0 @@ -module ActionController - module ActiveRecordRuntime - extend ActiveSupport::Concern - - attr_internal :db_runtime - - def cleanup_view_runtime - if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? - db_rt_before_render = ActiveRecord::Base.connection.reset_runtime - runtime = super - db_rt_after_render = ActiveRecord::Base.connection.reset_runtime - self.db_runtime = db_rt_before_render + db_rt_after_render - runtime - db_rt_after_render - else - super - end - end - - module ClassMethods - def process_log_action(controller) - super - db_runtime = controller.send :db_runtime - logger.info(" ActiveRecord runtime: %.1fms" % db_runtime.to_f) if db_runtime - end - end - end -end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/metal/logger.rb b/actionpack/lib/action_controller/metal/logger.rb index 5d14f6c9c9..e71f77fbb2 100644 --- a/actionpack/lib/action_controller/metal/logger.rb +++ b/actionpack/lib/action_controller/metal/logger.rb @@ -30,12 +30,22 @@ module ActionController end end - def cleanup_view_runtime + # If you want to remove any time taken into account in :view_runtime + # wrongly, you can do it here: + # + # def cleanup_view_runtime + # super - time_taken_in_something_expensive + # end + # + # :api: plugin + def cleanup_view_runtime #:nodoc: yield end module ClassMethods - def log_event(name, before, after, instrumenter_id, payload) + # This is the hook invoked by ActiveSupport::Notifications.subscribe. + # If you need to log any event, overwrite the method and do it here. + def log_event(name, before, after, instrumenter_id, payload) #:nodoc: if name == :process_action duration = [(after - before) * 1000, 0.01].max controller = payload[:controller] @@ -65,10 +75,11 @@ module ActionController protected # A hook which allows logging what happened during controller process action. + # :api: plugin def log_process_action(controller) #:nodoc: view_runtime = controller.send :view_runtime logger.info(" View runtime: %.1fms" % view_runtime.to_f) if view_runtime end end end -end +end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/rails.rb b/actionpack/lib/action_controller/rails.rb index e381828ee4..6ebb50887b 100644 --- a/actionpack/lib/action_controller/rails.rb +++ b/actionpack/lib/action_controller/rails.rb @@ -1,6 +1,7 @@ module ActionController class Plugin < Rails::Plugin plugin_name :action_controller + include_modules_in "ActionController::Base" initializer "action_controller.set_configs" do |app| app.config.action_controller.each do |k,v| |