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 38

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

.log_levels?Boolean (rw)

This method is for internal use only.
[ GitHub ]

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

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

.logger (rw)

[ GitHub ]

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

def logger
  @logger || default_logger
end

.logger=(value) (rw)

[ GitHub ]

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

attr_writer :logger

.namespace (rw)

[ GitHub ]

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

attr_accessor :namespace

Class Method Details

.default_logger

Raises:

  • (NotImplementedError)
[ GitHub ]

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

def default_logger
  raise NotImplementedError
end

.event_log_level(method_name, level)

[ GitHub ]

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

def event_log_level(method_name, level)
  log_levels[method_name.to_s] = level
end

.subscription_filter

[ GitHub ]

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

def subscription_filter
  namespace = self.namespace.to_s
  proc do |event|
    name = event[:name]
    if (dot_idx = name.index("."))
      event_namespace = name[0, dot_idx]
      namespace == event_namespace
    end
  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 38

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

#log_levels?Boolean (rw)

This method is for internal use only.
[ GitHub ]

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

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

Instance Method Details

#emit(event)

This method is for internal use only.
[ GitHub ]

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

def emit(event)
  return unless logger
  name = event[:name]
  event_method = name[name.index(".") + 1, name.length]

  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 57

def log_level_satisfied?(event_method)
  event_log_level = log_levels[event_method]
  return false unless LOG_LEVELS.include?(event_log_level)

  logger.public_send("#{event_log_level}?")
end

#logger

This method is for internal use only.
[ GitHub ]

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

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 53

def namespace
  self.class.namespace
end