提交 8f59ffce 编写于 作者: M Matthew M. Boedicker

Do not log the binding values for binary columns.

They tend to be large and not very useful in the log.
上级 fa3457dc
## 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.
......
......@@ -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
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册