Methods
Public Instance methods
Log and benchmark the workings of a single block and silence whatever logging that may have happened inside it (unless use_silence is set to false).
The benchmark is only recorded if the current level of the logger matches the log_level, which makes it easy to include benchmarking statements in production software that will remain inexpensive because the benchmark will only be conducted if the log level is low enough.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/benchmarking.rb, line 26 26: def benchmark(title, log_level = Logger::DEBUG, use_silence = true) 27: if logger && logger.level == log_level 28: result = nil 29: seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } 30: logger.add(log_level, "#{title} (#{'%.5f' % seconds})") 31: result 32: else 33: yield 34: end 35: end
Silences the logger for the duration of the block.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/benchmarking.rb, line 38 38: def silence 39: old_logger_level, logger.level = logger.level, Logger::ERROR if logger 40: yield 41: ensure 42: logger.level = old_logger_level if logger 43: end