diff options
Diffstat (limited to 'actionpack/lib/action_controller/abstract/logger.rb')
-rw-r--r-- | actionpack/lib/action_controller/abstract/logger.rb | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb index 4117369bd4..d6fa843485 100644 --- a/actionpack/lib/action_controller/abstract/logger.rb +++ b/actionpack/lib/action_controller/abstract/logger.rb @@ -1,7 +1,45 @@ +require 'active_support/core_ext/class/attribute_accessors' +require 'active_support/core_ext/logger' + module AbstractController module Logger - setup do + extend ActiveSupport::Concern + + class DelayedLog + def initialize(&blk) + @blk = blk + end + + def to_s + @blk.call + end + alias to_str to_s + end + + included do cattr_accessor :logger end + + def process(action) + ret = super + + if logger + log = 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 + + ret + end + + def request_origin + # this *needs* to be cached! + # otherwise you'd get different results if calling it more than once + @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}" + end end -end
\ No newline at end of file +end |