Class: ActionController::LogSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/sapience/extensions/action_controller/log_subscriber_processing.rb,
lib/sapience/extensions/action_controller/log_subscriber.rb

Overview

rubocop:disable ClassAndModuleChildren

Instance Method Summary collapse

Instance Method Details

#halted_callback(event) ⇒ Object



40
41
42
43
44
# File 'lib/sapience/extensions/action_controller/log_subscriber.rb', line 40

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

#process_action(event) ⇒ Object

rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sapience/extensions/action_controller/log_subscriber.rb', line 9

def process_action(event) # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
  controller_logger(event).info do
    payload = event.payload.dup
    payload[:params].except!(*INTERNAL_PARAMS)
    payload.delete(:params) if payload[:params].empty?

    format           = payload[:format]
    payload[:format] = format.to_s.upcase if format.is_a?(Symbol)

    payload[:path]   = extract_path(payload[:path]) if payload.key?(:path)

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

    # Rounds off the runtimes. For example, :view_runtime, :mongo_runtime, etc.
    payload.keys.each do |key|
      payload[key] = payload[key].to_f.round(2) if key.to_s.match(/(.*)_runtime/)
    end

    payload[:message]        = "Completed ##{payload[:action]}"
    payload[:status_message] = Rack::Utils::HTTP_STATUS_CODES[payload[:status]] if payload[:status].present?
    payload[:duration]       = event.duration
    # Causes excessive log output with Rails 5 RC1
    payload.delete(:headers)
    payload
  end
end

#redirect_to(event) ⇒ Object



50
51
52
# File 'lib/sapience/extensions/action_controller/log_subscriber.rb', line 50

def redirect_to(event)
  controller_logger(event).info("Redirected to") { { location: event.payload[:location] } }
end

#send_data(event) ⇒ Object



54
55
56
# File 'lib/sapience/extensions/action_controller/log_subscriber.rb', line 54

def send_data(event)
  controller_logger(event).info("Sent data") { { file_name: event.payload[:filename], duration: event.duration } }
end

#send_file(event) ⇒ Object



46
47
48
# File 'lib/sapience/extensions/action_controller/log_subscriber.rb', line 46

def send_file(event)
  controller_logger(event).info("Sent file") { { path: event.payload[:path], duration: event.duration } }
end

#start_processing(event) ⇒ Object

Log as debug to hide Processing messages in production



5
6
7
# File 'lib/sapience/extensions/action_controller/log_subscriber_processing.rb', line 5

def start_processing(event)
  controller_logger(event).info { "Processing ##{event.payload[:action]}" }
end

#unpermitted_parameters(event) ⇒ Object



58
59
60
61
62
63
# File 'lib/sapience/extensions/action_controller/log_subscriber.rb', line 58

def unpermitted_parameters(event)
  controller_logger(event).debug do
    unpermitted_keys = event.payload[:keys]
    "Unpermitted parameter#{"s" if unpermitted_keys.size > 1}: #{unpermitted_keys.join(", ")}"
  end
end