This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb | |
index b811e60..34323e3 100644 | |
--- a/app/controllers/application_controller.rb | |
+++ b/app/controllers/application_controller.rb | |
@@ -33,6 +33,38 @@ class ApplicationController < ActionController::Base | |
protected | |
+ # ActionController::Base calls this before processing each controller action. | |
+ # The default implementation produces two log entries: | |
+ # | |
+ # Processing <Controller>#<action> (for <client_ip> at <YYYY-MM-DD HH:MM:SS>) [<METHOD>] | |
+ # Parameters: {<foo>=><bar>} | |
+ # | |
+ # The first one identifies the endpoint, client IP, and timestamp, but the | |
+ # request parameters, which are of interest for any dynamic request, are in | |
+ # the second. This makes all kinds of analysis much harder. | |
+ # | |
+ # Therefore we override it to put all the information into a single log entry. | |
+ # | |
+ # See actionpack-2.3.5/lib/action_controller/base.rb for the original code. | |
+ def log_processing | |
+ if logger && logger.info? | |
+ # This part based on ActionController::Base#log_processing_for_request_id | |
+ message = "Processing #{self.class.name}\##{action_name} " | |
+ message << "to #{params[:format]} " if params[:format] | |
+ message << "(for #{request_origin}) [#{request.method.to_s.upcase}]" | |
+ | |
+ # This part based on ActionController::Base#log_processing_for_parameters | |
+ parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params.dup | |
+ parameters = parameters.except!(:controller, :action, :format, :_method) | |
+ | |
+ message << " Parameters: #{parameters.inspect}" unless parameters.empty? | |
+ | |
+ # ... and actually log it | |
+ logger.info(message) | |
+ end | |
+ end | |
+ | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment