Module: LogStruct::Integrations::RailsLogSubscribers

Extended by:
T::Sig
Defined in:
lib/log_struct/integrations/rails_log_subscribers.rb

Overview

Rails' own log subscribers, which LogStruct's lines replace

Class Method Summary collapse

Class Method Details

.detach(subscriber_class, namespace) ⇒ void

This method returns an undefined value.

Detaches a framework's log subscriber (ActiveStorage::LogSubscriber, :active_storage). Up to Rails 8.1 it's an ActiveSupport::LogSubscriber attached to the framework's notifications; from Rails 8.2 it's an ActiveSupport::EventReporter::LogSubscriber, subscribed to Rails.event when its file loads.

Parameters:

  • subscriber_class (T.untyped)
  • namespace (Symbol)


14
15
16
17
18
19
20
# File 'lib/log_struct/integrations/rails_log_subscribers.rb', line 14

def self.detach(subscriber_class, namespace)
  if subscriber_class.respond_to?(:detach_from)
    subscriber_class.detach_from(namespace)
  else
    unsubscribe_from_events(subscriber_class)
  end
end

.unsubscribe_from_events(subscriber_class) ⇒ void

This method returns an undefined value.

Unsubscribes a Rails 8.2 log subscriber from Rails.event. Does nothing for one that isn't subscribed there.

Parameters:

  • subscriber_class (T.untyped)


24
25
26
27
28
29
# File 'lib/log_struct/integrations/rails_log_subscribers.rb', line 24

def self.unsubscribe_from_events(subscriber_class)
  return unless ::ActiveSupport.respond_to?(:event_reporter)

  reporter = ::ActiveSupport.event_reporter
  reporter.unsubscribe(subscriber_class) if reporter.respond_to?(:unsubscribe)
end