From 5e8e8d6564b81514870773b3b5de9d5746b1f1e2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 6 Sep 2005 16:48:18 +0000 Subject: Added use_silence parameter to ActiveRecord::Base.benchmark that can be passed false to include all logging statements during the benchmark block. Added ActionController::Base.benchmark and ActionController::Base.silence to allow for easy benchmarking and turning off the log git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2140 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record/base.rb') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 6180f45fed..a6ce28685c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -714,11 +714,17 @@ module ActiveRecord #:nodoc: # project.create_manager("name" => "David") # project.milestones << Milestone.find(:all) # end - def benchmark(title) - result = nil - seconds = Benchmark.realtime { result = silence { yield } } - logger.info "#{title} (#{sprintf("%f", seconds)})" if logger - return result + # + # The loggings of the multiple statements is turned off unless use_silence is set to false. + def benchmark(title, use_silence = true) + if logger + result = nil + seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } + logger.info "#{title} (#{sprintf("%f", seconds)})" + result + else + yield + end end # Silences the logger for the duration of the block. -- cgit v1.2.3