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)
|
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
|
|
|
|
payload = event.payload
|
|
|
|
additions = ActionController::Base.log_process_action(payload)
|
|
|
|
|
|
|
|
status = payload[:status]
|
|
|
|
if status.nil? && payload[:exception].present?
|
|
|
|
exception_class_name = payload[:exception].first
|
|
|
|
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
|
|
|
end
|
2017-06-20 08:20:04 -04:00
|
|
|
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms".dup
|
2016-02-09 16:48:03 -05:00
|
|
|
message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
|
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]
|
2016-08-09 17:37:27 -04:00
|
|
|
"Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.map { |e| ":#{e}" }.join(", ")}"
|
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
|