123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::EventReporter::LogSubscriber

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: activesupport/lib/active_support/event_reporter/log_subscriber.rb

Constant Summary

::ActiveSupport::ColorizeLogging - Included

BLACK, BLUE, CYAN, GREEN, MAGENTA, MODES, RED, WHITE, YELLOW

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::ActiveSupport::ColorizeLogging - Included

#color

Set color by using a symbol or one of the defined constants.

#colorize_logging, #debug, #error, #fatal, #info, #mode_from, #unknown, #warn

Class Attribute Details

.log_levels (rw)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 55

class_attribute :log_levels, default: {}.freeze # :nodoc:

.log_levels? ⇒ Boolean (rw)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 55

class_attribute :log_levels, default: {}.freeze # :nodoc:

.logger (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 36

def logger
  @logger || default_logger
end

.logger=(value) (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 44

attr_writer :logger

.namespace (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 45

attr_accessor :namespace

Class Method Details

.default_logger

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 40

def default_logger
  raise NotImplementedError
end

.event_log_level(method_name, level)

[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 32

def event_log_level(method_name, level)
  self.log_levels = log_levels.merge(method_name.to_s => level).freeze
end

.event_method_for(name)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 17

def event_method_for(name) # :nodoc:
  methods = event_methods
  methods[name] || begin
    event_method = name[(name.index(".") || -1) + 1, name.length].freeze
    methods.compute_if_absent(-name.to_s) { event_method }
  end
end

.event_methods

Event name => event method name, shared across subclasses: the mapping is derived from the name alone, and computing it allocates a substring.

[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 27

def event_methods
  ActiveSupport::Ractors.store_if_absent(:active_support_event_log_subscriber_event_methods) { Concurrent::Map.new }
end

.subscription_filter

[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 47

def subscription_filter
  prefix = "#{namespace}.".freeze
  proc do |event|
    event[:name].start_with?(prefix)
  end
end

Instance Attribute Details

#log_levels (rw)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 55

class_attribute :log_levels, default: {}.freeze # :nodoc:

#log_levels? ⇒ Boolean (rw)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 55

class_attribute :log_levels, default: {}.freeze # :nodoc:

Instance Method Details

#consumes?(name) ⇒ Boolean

This method is for internal use only.

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.

[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 68

def consumes?(name)
  return false unless logger

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

#emit(event)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 57

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

#log_level_satisfied?(event_method) ⇒ Boolean (private)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 83

def log_level_satisfied?(event_method)
  predicate = LOG_LEVEL_PREDICATES[log_levels[event_method]]
  return false unless predicate

  logger.public_send(predicate)
end

#logger

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 74

def logger
  self.class.logger
end

#namespace (private)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 79

def namespace
  self.class.namespace
end