mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Clean up AbstractController::Logger and write documentation
This commit is contained in:
parent
f35f47b8c0
commit
b6fde6b480
1 changed files with 12 additions and 4 deletions
|
@ -5,6 +5,13 @@ module AbstractController
|
||||||
module Logger
|
module Logger
|
||||||
extend ActiveSupport::Concern
|
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
|
class DelayedLog
|
||||||
def initialize(&blk)
|
def initialize(&blk)
|
||||||
@blk = blk
|
@blk = blk
|
||||||
|
@ -20,8 +27,10 @@ module AbstractController
|
||||||
cattr_accessor :logger
|
cattr_accessor :logger
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(action)
|
# Override process_action in the AbstractController::Base
|
||||||
ret = super
|
# to log details about the method.
|
||||||
|
def process_action(action)
|
||||||
|
super
|
||||||
|
|
||||||
if logger
|
if logger
|
||||||
log = DelayedLog.new do
|
log = DelayedLog.new do
|
||||||
|
@ -32,10 +41,9 @@ module AbstractController
|
||||||
|
|
||||||
logger.info(log)
|
logger.info(log)
|
||||||
end
|
end
|
||||||
|
|
||||||
ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
def request_origin
|
def request_origin
|
||||||
# this *needs* to be cached!
|
# this *needs* to be cached!
|
||||||
# otherwise you'd get different results if calling it more than once
|
# otherwise you'd get different results if calling it more than once
|
||||||
|
|
Loading…
Reference in a new issue