1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_controller/abstract/logger.rb

45 lines
939 B
Ruby
Raw Normal View History

2009-05-14 04:56:07 -04:00
require 'active_support/core_ext/class/attribute_accessors'
module AbstractController
module Logger
2009-05-07 11:29:22 -04:00
extend ActiveSupport::DependencyModule
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
2009-05-14 04:56:07 -04:00
end