Skip to content

Instantly share code, notes, and snippets.

@sonots
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonots/f46b2d1b1fb7ca6f5513 to your computer and use it in GitHub Desktop.
Save sonots/f46b2d1b1fb7ca6f5513 to your computer and use it in GitHub Desktop.

NOTE: ActionController::LogSubscriber is not shown if you run at rails c. You need to run the code at controller or require 'action_controller/log_subscriber.rb' before runnig.

[1] pry(#<ActionController::LogSubscriber>)> 
ActiveSupport::Notifications.notifier.instance_variable_get("@subscribers").each {
 |t| p "#{t.instance_variable_get(:@delegate).class} #{t.instance_variable_get(:@pattern)}"
}; nil
"ActiveRecord::LogSubscriber render_bind.active_record"
"ActiveRecord::LogSubscriber sql.active_record"
"ActiveRecord::LogSubscriber odd?.active_record"
"ActiveRecord::LogSubscriber logger.active_record"
"ActiveRecord::ExplainSubscriber sql.active_record"
"ActionMailer::LogSubscriber deliver.action_mailer"
"ActionMailer::LogSubscriber receive.action_mailer"
"ActionMailer::LogSubscriber process.action_mailer"
"ActionMailer::LogSubscriber logger.action_mailer"
"ActionView::LogSubscriber render_template.action_view"
"ActionView::LogSubscriber render_partial.action_view"
"ActionView::LogSubscriber render_collection.action_view"
"ActionView::LogSubscriber logger.action_view"
"ActionController::LogSubscriber start_processing.action_controller"
"ActionController::LogSubscriber process_action.action_controller"
"ActionController::LogSubscriber halted_callback.action_controller"
"ActionController::LogSubscriber send_file.action_controller"
"ActionController::LogSubscriber redirect_to.action_controller"
"ActionController::LogSubscriber send_data.action_controller"
"ActionController::LogSubscriber unpermitted_parameters.action_controller"
"ActionController::LogSubscriber deep_munge.action_controller"
"ActionController::LogSubscriber write_fragment.action_controller"
"ActionController::LogSubscriber read_fragment.action_controller"
"ActionController::LogSubscriber exist_fragment?.action_controller"
"ActionController::LogSubscriber expire_fragment.action_controller"
"ActionController::LogSubscriber expire_page.action_controller"
"ActionController::LogSubscriber write_page.action_controller"
"ActionController::LogSubscriber logger.action_controller"
=> nil
@sonots
Copy link
Author

sonots commented Jul 2, 2014

Let's see instrument methods located at actionpack/lib/action_controller/log_subscriber.rb.
In this file, following code is executed at the bottom of the line.

ActionController::LogSubscriber.attach_to :action_controller

This call ActiveSupport::Notifications.subscribe for all methods in ActionController::LogSubscriber class, that is,

ActiveSupport::Notifications.subscribe "start_processing.action_controller"
ActiveSupport::Notifications.subscribe "process_action.action_controller"
...

@sonots
Copy link
Author

sonots commented Jul 2, 2014

To unscrbie them, call like

ActiveSupport::Notifications.unsubscribe "start_processing.action_controller"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment