2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-06-24 07:23:43 -04:00
|
|
|
module ActionController
|
|
|
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
|
|
|
INTERNAL_PARAMS = %w(controller action format _method only_path)
|
|
|
|
|
|
|
|
def start_processing(event)
|
2012-09-19 19:00:28 -04:00
|
|
|
return unless logger.info?
|
|
|
|
|
2010-06-24 07:23:43 -04:00
|
|
|
payload = event.payload
|
|
|
|
params = payload[:params].except(*INTERNAL_PARAMS)
|
2011-05-06 20:21:49 -04:00
|
|
|
format = payload[:format]
|
|
|
|
format = format.to_s.upcase if format.is_a?(Symbol)
|
2019-12-31 03:18:36 -05:00
|
|
|
format = "*/*" if format.nil?
|
2010-06-24 07:23:43 -04:00
|
|
|
|
2011-06-24 15:01:57 -04:00
|
|
|
info "Processing by #{payload[:controller]}##{payload[:action]} as #{format}"
|
2010-06-24 07:23:43 -04:00
|
|
|
info " Parameters: #{params.inspect}" unless params.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_action(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
info do
|
2018-10-09 14:08:25 -04:00
|
|
|
payload = event.payload
|
2014-07-18 02:27:08 -04:00
|
|
|
additions = ActionController::Base.log_process_action(payload)
|
|
|
|
status = payload[:status]
|
2018-10-09 14:08:25 -04:00
|
|
|
|
2019-07-31 04:28:18 -04:00
|
|
|
if status.nil? && (exception_class_name = payload[:exception].first)
|
2014-07-18 02:27:08 -04:00
|
|
|
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
|
|
|
end
|
2018-10-09 14:08:25 -04:00
|
|
|
|
|
|
|
additions << "Allocations: #{event.allocations}"
|
|
|
|
|
2018-05-17 04:32:27 -04:00
|
|
|
message = +"Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
|
2019-08-16 13:01:37 -04:00
|
|
|
message << " (#{additions.join(" | ")})"
|
2016-02-06 16:28:59 -05:00
|
|
|
message << "\n\n" if defined?(Rails.env) && Rails.env.development?
|
2016-02-03 03:03:31 -05:00
|
|
|
|
2014-07-18 02:27:08 -04:00
|
|
|
message
|
2011-06-24 15:01:57 -04:00
|
|
|
end
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
2011-11-30 03:52:52 -05:00
|
|
|
def halted_callback(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
info { "Filter chain halted as #{event.payload[:filter].inspect} rendered or redirected" }
|
2011-11-30 03:52:52 -05:00
|
|
|
end
|
|
|
|
|
2010-06-24 07:23:43 -04:00
|
|
|
def send_file(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
info { "Sent file #{event.payload[:path]} (#{event.duration.round(1)}ms)" }
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_to(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
info { "Redirected to #{event.payload[:location]}" }
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def send_data(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
info { "Sent data #{event.payload[:filename]} (#{event.duration.round(1)}ms)" }
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
2013-03-07 04:41:05 -05:00
|
|
|
def unpermitted_parameters(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
debug do
|
|
|
|
unpermitted_keys = event.payload[:keys]
|
2018-12-03 19:40:46 -05:00
|
|
|
color("Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.map { |e| ":#{e}" }.join(", ")}", RED)
|
2014-07-18 02:27:08 -04:00
|
|
|
end
|
2013-03-07 04:41:05 -05:00
|
|
|
end
|
|
|
|
|
2010-06-24 07:23:43 -04:00
|
|
|
%w(write_fragment read_fragment exist_fragment?
|
|
|
|
expire_fragment expire_page write_page).each do |method|
|
|
|
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
|
|
|
def #{method}(event)
|
2016-07-14 06:38:16 -04:00
|
|
|
return unless logger.info? && ActionController::Base.enable_fragment_cache_logging
|
2017-05-18 12:12:32 -04:00
|
|
|
key = ActiveSupport::Cache.expand_cache_key(event.payload[:key] || event.payload[:path])
|
2010-06-24 07:23:43 -04:00
|
|
|
human_name = #{method.to_s.humanize.inspect}
|
2017-05-18 12:12:32 -04:00
|
|
|
info("\#{human_name} \#{key} (\#{event.duration.round(1)}ms)")
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
METHOD
|
|
|
|
end
|
2016-08-07 13:12:10 -04:00
|
|
|
|
2010-06-24 07:23:43 -04:00
|
|
|
def logger
|
|
|
|
ActionController::Base.logger
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-24 15:01:57 -04:00
|
|
|
ActionController::LogSubscriber.attach_to :action_controller
|