123456789_123456789_123456789_123456789_123456789_

Class: ActionController::LogSubscriber

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveSupport::EventReporter::LogSubscriber
Defined in: actionpack/lib/action_controller/log_subscriber.rb

Constant Summary

::ActiveSupport::ColorizeLogging - Included

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

::ActiveSupport::EventReporter::LogSubscriber - Inherited

LEVEL_CHECKS

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Attribute Details

.backtrace_cleaner (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 7

class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new

.backtrace_cleaner?Boolean (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 7

class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new

Class Method Details

.default_logger

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 100

def self.default_logger
  ActionController::Base.logger
end

Instance Attribute Details

#backtrace_cleaner (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 7

class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new

#backtrace_cleaner?Boolean (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 7

class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new

Instance Method Details

#callback_halted(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 47

def callback_halted(event)
  info { "Filter chain halted as #{event[:payload][:filter].inspect} rendered or redirected" }
end

#data_sent(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 75

def data_sent(event)
  info { "Sent data #{event[:payload][:filename]} (#{event[:payload][:duration_ms].round(1)}ms)" }
end

#file_sent(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 61

def file_sent(event)
  info { "Sent file #{event[:payload][:path]} (#{event[:payload][:duration_ms].round(1)}ms)" }
end

#fragment_cache(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 90

def fragment_cache(event)
  return unless ActionController::Base.enable_fragment_cache_logging

  key        = event[:payload][:key]
  human_name = event[:payload][:method].to_s.humanize

  info("#{human_name} #{key} (#{event[:payload][:duration_ms]}ms)")
end

#redirect_source_location (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 105

def redirect_source_location
  backtrace_cleaner.first_clean_frame
end

#redirected(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 66

def redirected(event)
  info { "Redirected to #{event[:payload][:location]}" }

  if ActionDispatch.verbose_redirect_logs && (source = redirect_source_location)
    info { "#{source}" }
  end
end

#request_completed(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 26

def request_completed(event)
  info do
    payload = event[:payload]
    additions = ActionController::Base.log_process_action(payload)
    status = payload[:status]

    if status.nil? && (exception_class_name = payload[:exception]&.first)
      status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
    end

    additions << "GC: #{payload[:gc_time_ms].round(1)}ms"

    message = +"Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{payload[:duration_ms].round(0)}ms" \
               " (#{additions.join(" | ")})"
    message << "\n\n" if defined?(Rails.env) && Rails.env.development?

    message
  end
end

#request_started(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 11

def request_started(event)
  payload = event[:payload]
  params = {}
  payload[:params].each_pair do |k, v|
    params[k] = v unless INTERNAL_PARAMS.include?(k)
  end
  format  = payload[:format]
  format  = format.to_s.upcase if format.is_a?(Symbol)
  format  = "*/*" if format.nil?

  info "Processing by #{payload[:controller]}##{payload[:action]} as #{format}"
  info "  Parameters: #{params.inspect}" unless params.empty?
end

#rescue_from_handled(event)

Manually subscribed below

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 53

def rescue_from_handled(event)
  exception_class = event[:payload][:exception_class]
  exception_message = event[:payload][:exception_message]
  exception_backtrace = event[:payload][:exception_backtrace]
  info { "rescue_from handled #{exception_class} (#{exception_message}) - #{exception_backtrace.first.delete_prefix("#{Rails.root}/")}" }
end

#unpermitted_parameters(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/log_subscriber.rb', line 80

def unpermitted_parameters(event)
  debug do
    unpermitted_keys = event[:payload][:unpermitted_keys]
    display_unpermitted_keys = unpermitted_keys.map { |e| ":#{e}" }.join(", ")
    context = event[:payload][:context].map { |k, v| "#{k}: #{v}" }.join(", ")
    color("Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{display_unpermitted_keys}. Context: { #{context} }", RED)
  end
end