aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/log_subscriber.rb12
-rw-r--r--activerecord/test/cases/log_subscriber_test.rb8
3 files changed, 23 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index be3b6564b0..595bf4db72 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Do not log the binding values for binary columns.
+
+ *Matthew M. Boedicker*
+
* Fix counter cache columns not updated when replacing `has_many :through`
associations.
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb
index ca79950049..11ec2eaf79 100644
--- a/activerecord/lib/active_record/log_subscriber.rb
+++ b/activerecord/lib/active_record/log_subscriber.rb
@@ -20,6 +20,16 @@ module ActiveRecord
@odd_or_even = false
end
+ def render_bind(column, value)
+ if column.type == :binary
+ rendered_value = "<#{value.bytesize} bytes of binary data>"
+ else
+ rendered_value = value
+ end
+
+ [column.name, rendered_value]
+ end
+
def sql(event)
self.class.runtime += event.duration
return unless logger.debug?
@@ -34,7 +44,7 @@ module ActiveRecord
unless (payload[:binds] || []).empty?
binds = " " + payload[:binds].map { |col,v|
- [col.name, v]
+ render_bind(col, v)
}.inspect
end
diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb
index 70d00aecf9..8f42c8ef7b 100644
--- a/activerecord/test/cases/log_subscriber_test.rb
+++ b/activerecord/test/cases/log_subscriber_test.rb
@@ -1,4 +1,5 @@
require "cases/helper"
+require "models/binary"
require "models/developer"
require "models/post"
require "active_support/log_subscriber/test_helper"
@@ -100,4 +101,11 @@ class LogSubscriberTest < ActiveRecord::TestCase
def test_initializes_runtime
Thread.new { assert_equal 0, ActiveRecord::LogSubscriber.runtime }.join
end
+
+ def test_binary_data_is_not_logged
+ Binary.create(:data => 'some binary data')
+ wait
+ assert_equal 3, @logger.logged(:debug).size
+ assert_match(/<16 bytes of binary data>/, @logger.logged(:debug)[-2])
+ end
end