ActiveSupport::Notifications.subscribe do |name, start, finish, id, payload| Rails.logger.debug(["notification:", name, start, finish, id, payload].join(" ")) end
Started GET "/" for 127.0.0.1 at 2012-09-26 14:40:43 +0800 Processing by WelcomeController#index as HTML notification: start_processing.action_controller 2012-09-26 14:40:43 +0800 2012-09-26 14:40:43 +0800 7b8c2a131277e455e268 {:controller=>"WelcomeController", :action=>"index", :params=>{"controller"=>"welcome", "action"=>"index"}, :format=>:html, :method=>"GET", :path=>"/"} User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 notification: sql.active_record 2012-09-26 14:40:43 +0800 2012-09-26 14:40:43 +0800 7b8c2a131277e455e268 {:sql=>"SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1", :name=>"User Load", :connection_id=>97717390, :binds=>[]} Read fragment views/127.0.0.1:3000/index (0.2ms) notification: read_fragment.action_controller 2012-09-26 14:40:43 +0800 2012-09-26 14:40:43 +0800 7b8c2a131277e455e268 {:key=>"views/127.0.0.1:3000/index"} Completed 200 OK in 3ms (ActiveRecord: 0.1ms) notification: process_action.action_controller 2012-09-26 14:40:43 +0800 2012-09-26 14:40:43 +0800 7b8c2a131277e455e268 {:controller=>"WelcomeController", :action=>"index", :params=>{"controller"=>"welcome", "action"=>"index"}, :format=>:html, :method=>"GET", :path=>"/", :status=>200, :view_runtime=>nil, :db_runtime=>0.143454}
start_processing.action_controller 2012-09-26 14:40:43 +0800 2012-09-26 14:40:43 +0800 7b8c2a131277e455e268 {:controller=>"WelcomeController", :action=>"index", :params=>{"controller"=>"welcome", "action"=>"index"}, :format=>:html, :method=>"GET", :path=>"/"}
start_processing.action_controller notification: sql.active_record notification: sql.active_record notification: sql.active_record notification: !render_template.action_view notification: !render_template.action_view notification: render_template.action_view notification: process_action.action_controller
class Product < ActiveRecord::Base def self.search(search) if search ActiveSupport::Notifications.instrument("products.search", :search => search) where('name LIKE ?', "%#{search}%") else scoped end end end
ActiveSupport::Notifications.subscribe "products.search" do |name, start, finish, id, payload| Rails.logger.debug "SEARCH: #{payload[:search]}" end