Skip to Content Skip to Search
Methods
C
D
E
L
S

Constants

LOG_LEVELS = [:debug, :info, :warn, :error].freeze
 

Attributes

[W] logger
[RW] namespace

Class Public methods

default_logger()

# File activesupport/lib/active_support/event_reporter/log_subscriber.rb, line 45
def default_logger
  raise NotImplementedError
end

event_log_level(method_name, level, if: nil)

Sets the level an event is logged at. With if, the event is only logged while the condition returns true.

event_log_level :fragment_cache, :info, if: -> { ActionController::Base.enable_fragment_cache_logging }

# File activesupport/lib/active_support/event_reporter/log_subscriber.rb, line 35
def event_log_level(method_name, level, if: nil)
  self.log_levels = log_levels.merge(method_name.to_s => level).freeze
  condition = binding.local_variable_get(:if)
  self.log_conditions = ActiveSupport::Ractors.try_make_shareable(log_conditions.merge(method_name.to_s => condition)).freeze
end

logger()

# File activesupport/lib/active_support/event_reporter/log_subscriber.rb, line 41
def logger
  @logger || default_logger
end

subscription_filter()

# File activesupport/lib/active_support/event_reporter/log_subscriber.rb, line 52
def subscription_filter
  prefix = "#{namespace}.".freeze
  proc do |event|
    event[:name].start_with?(prefix)
  end
end

Instance Public methods

consumes?(name)

Whether an event with this name would currently be logged, so that the event reporter can skip building events this subscriber would discard. Deliberately not memoized: the answer changes with the logger’s level.

# File activesupport/lib/active_support/event_reporter/log_subscriber.rb, line 74
def consumes?(name)
  return false unless logger

  log_level_satisfied?(self.class.event_method_for(name))
end

emit(event)

# File activesupport/lib/active_support/event_reporter/log_subscriber.rb, line 63
def emit(event)
  return unless logger
  event_method = self.class.event_method_for(event[:name])

  public_send(event_method, event) if log_level_satisfied?(event_method)
end

logger()

# File activesupport/lib/active_support/event_reporter/log_subscriber.rb, line 80
def logger
  self.class.logger
end