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 actionpack/lib/action_controller/benchmarking.rb, line 23 23: def benchmark(title, log_level = Logger::DEBUG, use_silence = true) 24: if logger && logger.level == log_level 25: result = nil 26: ms = Benchmark.ms { result = use_silence ? silence { yield } : yield } 27: logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)") 28: result 29: else 30: yield 31: end 32: end
Silences the logger for the duration of the block.
[ show source ]
# File actionpack/lib/action_controller/benchmarking.rb, line 35 35: def silence 36: old_logger_level, logger.level = logger.level, Logger::ERROR if logger 37: yield 38: ensure 39: logger.level = old_logger_level if logger 40: end