From be408bd4c6412cc2646731e0740dcefa4e0fc775 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 11 Mar 2007 12:30:28 +0000 Subject: [PATCH] Fix @logger.debug? conditional considering @logger may be nil. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6375 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../connection_adapters/abstract_adapter.rb | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 11112106f7..fc29f11e15 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -23,7 +23,7 @@ module ActiveRecord class AbstractAdapter include Quoting, DatabaseStatements, SchemaStatements @@row_even = true - + def initialize(connection, logger = nil) #:nodoc: @connection, @logger = connection, logger @runtime = 0 @@ -41,7 +41,7 @@ module ActiveRecord def supports_migrations? false end - + # Does this adapter support using DISTINCT within COUNT? This is +true+ # for all adapters except sqlite. def supports_count_distinct? @@ -86,7 +86,7 @@ module ActiveRecord end # Lazily verify this connection, calling +active?+ only if it hasn't - # been called for +timeout+ seconds. + # been called for +timeout+ seconds. def verify!(timeout) now = Time.now.to_i if (now - @last_verification) > timeout @@ -94,24 +94,20 @@ module ActiveRecord @last_verification = now end end - + # Provides access to the underlying database connection. Useful for # when you need to call a proprietary method such as postgresql's lo_* # methods def raw_connection @connection end - - def log_info(sql, name, runtime) - return unless @logger or !@logger.debug? - @logger.debug( - format_log_entry( - "#{name.nil? ? "SQL" : name} (#{sprintf("%f", runtime)})", - sql.gsub(/ +/, " ") - ) - ) - end + def log_info(sql, name, runtime) + if @logger && @logger.debug? + name = "#{name.nil? ? "SQL" : name} (#{sprintf("%f", runtime)})" + @logger.debug format_log_entry(name, sql.squeeze(' ')) + end + end protected def log(sql, name)