在Rails 3中禁用BLOB记录 [英] Disable BLOB logging in Rails 3

查看:107
本文介绍了在Rails 3中禁用BLOB记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来禁用/截断的记录SQL查询的BLOB字段?当我插入或更新纪录的BLOB字段在它的Rails记录器打印这些领域,这是非常恼人的内容。我找到了一些解决方案,但它们都没有使用Rails工作3。

Is there a way to disable/truncate BLOB fields in the logged SQL queries? When I insert or update a record with 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.

推荐答案

我认为有几件事情可以做,一将覆盖记录器format_message功能,从记录器消息中删除BLOB字段:

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

接下来将是你的BLOB字段添加到filter_parameters在application.rb中的文件。这将意味着BLOB字段将被过滤从您的应用程序完全记录:

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.

这篇关于在Rails 3中禁用BLOB记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆