Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

owst
Copy link

@owst owst commented Jan 24, 2024

Fixes #385

Assumes that a built-in subscriber is nested under the component namespace, so under ActionView or ActionController.

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([])
Copy link
Author

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)
Copy link
Author

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}::")
Copy link
Author

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

@owst owst changed the title Unsubscribe all built-in subscribers Unsubscribe all Rails built-in subscribers Jan 24, 2024
@trobrock
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActionView logs not completely suppressed with Rails 7.1+
2 participants