aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/logger.rb
blob: 956d7dd371b655a0dc4b5e56376c71773571c871 (plain) (blame)
1
2
3
4
5
6
7
8
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
require 'abstract_controller/logger'

module ActionController
  module Logger
    # Override process_action in the AbstractController::Base
    # to log details about the method.
    def process_action(action)
      result = ActiveSupport::Notifications.instrument(:process_action,
                :controller => self, :action => action) do
        super
      end

      if logger
        log = AbstractController::Logger::DelayedLog.new do
          "\n\nProcessing #{self.class.name}\##{action_name} " \
          "to #{request.formats} (for #{request_origin}) " \
          "[#{request.method.to_s.upcase}]"
        end

        logger.info(log)
      end

      result
    end

  private

    # Returns the request origin with the IP and time. This needs to be cached,
    # otherwise we would get different results for each time it calls.
    def request_origin
      @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
    end
  end
end