Search code examples
mysqlruby-on-railsactiverecordruby-on-rails-2ruby-1.8

Avoid ActiveRecord#save logging of large fields


I need to prevent ActiveRecord#save from logging the content of large fields.

Is there a way to configure this on Rails 2.3.x?

@document.save #=> Will log something like:

Apr 20 13:45:42 ubuntu rails[2619]: Document::HTML Update (7.0ms)   UPDATE `documents` SET `some_meta_data` = 1, `more_meta_data` = 2, `document_content` = '\n\n\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional.....................'
Apr 20 13:45:42 ubuntu rails[2619]: SQL (5.8ms)   COMMIT

I don't want the field document_content to be logged since is of type mysql 'text'.


Solution

  • If you are using rails 3, do something like this in config/application.rb:

    config.filter_parameters += [:password, :document_content]
    

    Then restart your app. From that point on the log should show something like 'document_content' = [ FILTERED ] if memory serves me right.

    If you are using rails 2, you need to put the following inside your controller:

    filter_parameter_logging :document_content
    

    You can append a comma separated list of fields if needed.