diff options
Diffstat (limited to 'activerecord')
5 files changed, 35 insertions, 46 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb index 00c71090f3..020acbbe5a 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -75,7 +75,8 @@ module ActiveRecord def cache_sql(sql) result = if @query_cache.has_key?(sql) - log_info(sql, "CACHE", 0.0) + ActiveSupport::Notifications.instrument("active_record.sql", + :sql => sql, :name => "CACHE", :connection_id => self.object_id) @query_cache[sql] else @query_cache[sql] = yield diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 1b8d3f7a05..4a9cc09032 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -190,13 +190,6 @@ module ActiveRecord "active_record_#{open_transactions}" end - def log_info(sql, name, ms) - if @logger && @logger.debug? - name = '%s (%.1fms)' % [name, ms] - @logger.debug(format_log_entry(name, sql.squeeze(' '))) - end - end - protected def log(sql, name) name ||= "SQL" @@ -208,7 +201,7 @@ module ActiveRecord result rescue Exception => e message = "#{e.class.name}: #{e.message}: #{sql}" - log_info(message, name, 0) + @logger.debug message if @logger raise translate_exception(e, message) end @@ -217,23 +210,6 @@ module ActiveRecord ActiveRecord::StatementInvalid.new(message) end - def format_log_entry(message, dump = nil) - if ActiveRecord::Base.colorize_logging - if @@row_even - @@row_even = false - message_color, dump_color = "4;36;1", "0;1" - else - @@row_even = true - message_color, dump_color = "4;35;1", "0" - end - - log_entry = " \e[#{message_color}m#{message}\e[0m " - log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump - log_entry - else - "%s %s" % [message, dump] - end - end end end end diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index a07f33503d..88d0aa624f 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -14,6 +14,10 @@ module ActiveRecord load "active_record/railties/databases.rake" end + # TODO If we require the wrong file, the error never comes up. + require "active_record/railties/subscriber" + subscriber ActiveRecord::Railties::Subscriber.new + initializer "active_record.set_configs" do |app| app.config.active_record.each do |k,v| ActiveRecord::Base.send "#{k}=", v @@ -59,14 +63,6 @@ module ActiveRecord ActiveRecord::Base.logger ||= ::Rails.logger end - initializer "active_record.notifications" do - require 'active_support/notifications' - - ActiveSupport::Notifications.subscribe("active_record.sql") do |name, before, after, instrumenter_id, payload| - payload[:connection].log_info(payload[:sql], payload[:name], (after - before) * 1000) - end - end - initializer "active_record.i18n_deprecation" do require 'active_support/i18n' diff --git a/activerecord/lib/active_record/railties/subscriber.rb b/activerecord/lib/active_record/railties/subscriber.rb new file mode 100644 index 0000000000..fd873dbff8 --- /dev/null +++ b/activerecord/lib/active_record/railties/subscriber.rb @@ -0,0 +1,27 @@ +module ActiveRecord + module Railties + class Subscriber < Rails::Subscriber + def sql(event) + name = '%s (%.1fms)' % [event.payload[:name], event.duration] + sql = event.payload[:sql].squeeze(' ') + + if odd? + name = color(name, :cyan, true) + sql = color(sql, nil, true) + else + name = color(name, :magenta, true) + end + + debug " #{name} #{sql}" + end + + def odd? + @odd_or_even = !@odd_or_even + end + + def logger + ActiveRecord::Base.logger + end + end + end +end
\ No newline at end of file diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb index 4e54079ba5..94d6663778 100644 --- a/activerecord/test/cases/pooled_connections_test.rb +++ b/activerecord/test/cases/pooled_connections_test.rb @@ -137,15 +137,4 @@ class PooledConnectionsTest < ActiveRecord::TestCase def add_record(name) ActiveRecord::Base.connection_pool.with_connection { Project.create! :name => name } end -end unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name - -class AllowConcurrencyDeprecatedTest < ActiveRecord::TestCase - def test_allow_concurrency_is_deprecated - assert_deprecated('ActiveRecord::Base.allow_concurrency') do - ActiveRecord::Base.allow_concurrency - end - assert_deprecated('ActiveRecord::Base.allow_concurrency=') do - ActiveRecord::Base.allow_concurrency = true - end - end -end +end unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name
\ No newline at end of file |