2

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'.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110

1 Answers1

2

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.

brettish
  • 2,628
  • 3
  • 17
  • 22
  • @elgalu I edited the question to add rails 2 support. But, I have only used rails 3 so let me know if it works. – brettish Apr 20 '11 at 18:36
  • Unfortunately that's only filtering the logging of HTTP params but still logs the ActiveRecord#save sql query. – Leo Gallucci Apr 20 '11 at 18:55
  • @elgalu Thats right, with SQL logging it is all or nothing. You could turn off SQL logging in development mode if you really want to. In production mode, SQL logging is off by default. – brettish Apr 20 '11 at 19:00
  • Yes, i need this for development log since i don't want to see large field values while i'm developing, thanks anyway! – Leo Gallucci Apr 20 '11 at 21:02