diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-06 17:07:08 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-06 17:07:08 +0000 |
commit | 291c667d6614ce28f85311f06ceb5f130b903be1 (patch) | |
tree | f991d6aa20b0dad8cd948111813e48acee5c72d9 /actionpack/lib/action_controller/benchmarking.rb | |
parent | 5e8e8d6564b81514870773b3b5de9d5746b1f1e2 (diff) | |
download | rails-291c667d6614ce28f85311f06ceb5f130b903be1.tar.gz rails-291c667d6614ce28f85311f06ceb5f130b903be1.tar.bz2 rails-291c667d6614ce28f85311f06ceb5f130b903be1.zip |
Only do benchmarking if log level matches and log caching
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2141 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/benchmarking.rb')
-rw-r--r-- | actionpack/lib/action_controller/benchmarking.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/benchmarking.rb b/actionpack/lib/action_controller/benchmarking.rb index b7c7eae8e9..587bc29d42 100644 --- a/actionpack/lib/action_controller/benchmarking.rb +++ b/actionpack/lib/action_controller/benchmarking.rb @@ -19,11 +19,15 @@ module ActionController #:nodoc: module ClassMethods # Log and benchmark the workings of a single block and silence whatever logging that may have happened inside it # (unless <tt>use_silence</tt> is set to false). - def benchmark(title, use_silence = true) - if logger + # + # The benchmark is only recorded if the current level of the logger matches the <tt>log_level</tt>, 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. + def benchmark(title, log_level = Logger::DEBUG, use_silence = true) + if logger && logger.level == log_level result = nil seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } - logger.info "#{title} (#{sprintf("%f", seconds)})" + logger.add(log_level, "#{title} (#{sprintf("%f", seconds)})") result else yield |