-
-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsubscribe all Rails built-in subscribers #386
base: master
Are you sure you want to change the base?
Unsubscribe all Rails built-in subscribers #386
Conversation
Fixes roidrage#385 Assumes that a built-in subscriber is nested under the component namespace, so under ActionView or ActionController.
end | ||
|
||
it 'removes subscribers for all events' do | ||
expect do | ||
Lograge.remove_existing_log_subscriptions | ||
end.to change { | ||
Lograge.notification_listeners_for('render_template.action_view') | ||
} | ||
}.to([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This spec failed after this change on Rails 7.1
it "does not remove subscribers that aren't from Rails" do | ||
proc_subscriber = ActiveSupport::Notifications.subscribe(event_name, proc {}) | ||
custom_subscriber = | ||
ActiveSupport::Notifications.subscribe(event_name, CustomListener.new) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also check a custom class, in case there was some special handling of Proc
instances
delegate = listener.instance_variable_get('@delegate') | ||
|
||
# Assume that anything nested under the component namespace is built in to Rails | ||
delegate.class.name.start_with?("#{component.to_s.classify}::") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is great, but I can't see a better way to check if the delegate is subscriber
or (for Rails 7.1+) an instance of ActionView::LogSubscriber::Start
for ActionView
or subscriber
for ActionController
Hey any progress on this? I'm using the branch in production to help our logs. Would love to see this merged. Anything I can help with? |
Fixes #385
Assumes that a built-in subscriber is nested under the component namespace, so under ActionView or ActionController.