开发者

Disable BLOB logging in Rails 3

开发者 https://www.devze.com 2023-02-10 03:09 出处:网络
Is there a way to disable/truncate BLOB fields in the logged SQL queries? When I insert or update a record wi开发者_JS百科th BLOB fields in it Rails logger prints the contents of these fields which is

Is there a way to disable/truncate BLOB fields in the logged SQL queries? When I insert or update a record wi开发者_JS百科th BLOB fields in it Rails logger prints the contents of these fields which is very annoying. I found some solutions but none of them work with Rails 3.


I think there are a couple of things you can do, one would be to override the Logger format_message function and remove BLOB fields from the logger message:

class Logger
  def remove_blobs msg
    ...
  end

  def format_message(severity, timestamp, progname, msg)
    "#{remove_blobs msg}\n"
  end
end

The next would be to add your blob fields to the filter_parameters in your application.rb file. This would mean that the blob fields would be filtered from your application logs entirely:

config.filter_parameters += [:blob_field1, :blob_field2]

Finally, you could look into some other logging gems, like logging, to add further customization to your logs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号