Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Do not log the binding values for binary columns.

They tend to be large and not very useful in the log.
  • Loading branch information...
commit 8f59ffce671c9b467b0f97b420305a9faa5214d8 1 parent fa3457d
@mmb mmb authored
View
4 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.
View
12 activerecord/lib/active_record/log_subscriber.rb
@@ -20,6 +20,16 @@ def initialize
@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 @@ def sql(event)
unless (payload[:binds] || []).empty?
binds = " " + payload[:binds].map { |col,v|
- [col.name, v]
+ render_bind(col, v)
}.inspect
end
View
8 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 @@ def test_cached_queries_doesnt_log_when_level_is_not_debug
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

0 comments on commit 8f59ffc

Please sign in to comment.
Something went wrong with that request. Please try again.