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
|
|
|
|
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
|
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]
|
|
|
|
"Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.join(", ")}"
|
|
|
|
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)
|
2012-09-19 19:00:28 -04:00
|
|
|
return unless logger.info?
|
2010-06-24 07:23:43 -04:00
|
|
|
key_or_path = event.payload[:key] || event.payload[:path]
|
|
|
|
human_name = #{method.to_s.humanize.inspect}
|
2012-09-19 19:00:28 -04:00
|
|
|
info("\#{human_name} \#{key_or_path} (\#{event.duration.round(1)}ms)")
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
METHOD
|
|
|
|
end
|
|
|
|
|
|
|
|
def logger
|
|
|
|
ActionController::Base.logger
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-24 15:01:57 -04:00
|
|
|
ActionController::LogSubscriber.attach_to :action_controller
|