4

I've figured out how to silence the contents of an action by wrapping everything inside the action's method in a logger.silence block.

However, I still get the call to the action showing up in the log file.

I.E:

Processing DashboardController#update (for 66.201.17.166 at 2009-09-09 19:03:27) [GET]
  Parameters: {"todos"=>{"user"=>"25", "sfu_type"=>""}}
Completed in 1021ms (View: 439, DB: 438) | 200 OK [http://my.host.com/dashboard/update?todos%5Buser%5D=25&todos%5Bsfu_type%5D=]

I want to either keep the above from getting written to the logs all together, or redirect it to a different log file (i.e. dashboard.log) so it stops cluttering up the production.log file.

I get the above sample written to the log each time the ajax call updates for each user logged in. This updates about every 2 minutes so the production log file is getting flooded with unuseful log messages.

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
Streamline
  • 2,040
  • 4
  • 37
  • 56

5 Answers5

8

Late answer, but I spent quite a bit of time of the interwebs looking for the answer, which is thus:

In the controller that contains the action you would like to ignore, override the logger method and return the rails default for some actions, and a custom logger or nil for the ones that need special handling.

def logger
  if params[:action] == 'action_to_ignore'
    # return custom logger or nil
  else
    RAILS_DEFAULT_LOGGER
  end
end

I suspect there is an easier way, and would love to hear it if it exists.

fl00r
  • 82,987
  • 33
  • 217
  • 237
KalaATX
  • 96
  • 1
  • 2
  • Seems to work for me on Rails 3, and also work when running :production environment locally, but doesn't seem to work on Heroku. More specifically Heroku keeps outputing the "Render" messages. Any ideas? – Alon Burg Mar 20 '13 at 02:25
1

The logger calls are scattered all over ActionController::Base. The only way I can think of is to monkey patch a bunch of methods and check for the name of the controller in question.

Perhaps overriding this method is all you need to do. Not sure. Good luck :)

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
  • this likely the only available way to remove the logging of this info - will have to investigate this at some point to see - thanks – Streamline Sep 18 '09 at 18:21
  • FYI, just did something similar myself. If you override the `logger` instance method of a controller, you'll disable logging altogether. – August Lilleaas Sep 18 '09 at 19:42
1

This looks like a really good, flexible solution using middleware: http://dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/

Tyler Rick
  • 9,191
  • 6
  • 60
  • 60
0

Have you set your production logging level?

config > environments > production.rb

config.log_level = :warn (default is :info)

Reuben Mallaby
  • 5,740
  • 4
  • 47
  • 45
0

In the application controller you could override the logger:

def log_error(exception)
  #super(exception)
  #do my logging here
end

I use this to email me when errors occur in a critical app.

Reuben Mallaby
  • 5,740
  • 4
  • 47
  • 45
  • Or I could anwser your question instead of writing what I'm doing – Reuben Mallaby Sep 10 '09 at 16:52
  • Reuben, I think that would still just handle the logging that happens after the controller action is called vs modifying the logged info call to the controller / action - correct? – Streamline Sep 18 '09 at 18:19