Permalink
Browse files

Clean up AbstractController::Logger and write documentation

  • Loading branch information...
Yehuda Katz + Carl Lerche
Yehuda Katz + Carl Lerche committed Jun 10, 2009
1 parent f35f47b commit b6fde6b4801fae26cdd0e790f6bfd06e7afe9941
Showing with 12 additions and 4 deletions.
  1. +12 −4 actionpack/lib/action_controller/abstract/logger.rb
@@ -5,6 +5,13 @@ module AbstractController
module Logger
extend ActiveSupport::Concern
+ # A class that allows you to defer expensive processing
+ # until the logger actually tries to log. Otherwise, you are
+ # forced to do the processing in advance, and send the
+ # entire processed String to the logger, which might
+ # just discard the String if the log level is too low.
+ #
+ # TODO: Require that Rails loggers accept a block.
class DelayedLog
def initialize(&blk)
@blk = blk
@@ -20,8 +27,10 @@ def to_s
cattr_accessor :logger
end
- def process(action)
- ret = super
+ # Override process_action in the AbstractController::Base
+ # to log details about the method.
+ def process_action(action)
+ super
if logger
log = DelayedLog.new do
@@ -32,10 +41,9 @@ def process(action)
logger.info(log)
end
-
- ret
end
+ private
def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once

0 comments on commit b6fde6b

Please sign in to comment.