Suppress Rails logging
Dax Huiberts wo 28 jul 10
When Rails applications get rather complex the amount of log statements can get rather big in development mode. It is not uncommon to get hundreds of lines of SQL log statements.
This creates a problem when you try to insert your own log statements. With all the noise it gets pretty difficult to filter out your own log statements. One way is to prefix your statements with “>>>>>>>>>>” or “==” (or many more of those). If that doesn’t even help there is alway the ‘tail -f log/development.log | grep =’. This is not a very workable sollution either. In this case you also miss your request information. Like how long the request takes or what the request parameters are.
I’ve been using the following code snippet for a week now and it really meets my need:
# config/initializers/suppress_rails_logging.rb # suppress active record sql logging class ActiveRecord::ConnectionAdapters::AbstractAdapter def log_info(*args); end end # suppress 'rendered partial ...' logging module ActionView::RenderablePartial def render(view, local_assigns = {}) super end end
This snippet of code suppresses the ActiveRecord SQL logging statements and the ActionView ‘rendered partial …’ logging statements. It makes my logs useable again and I still don’t lose my request information logging statements.
Try it out and see for yourself wether this works for you. Please leave a comment for any feedback you have.
Gepost in hor | 1 reactie
Welcome to Holland On Rails
This weblog is the official Ruby techblog from the guys at Holder, a Ruby development company. Holder is also the company behind the RubyAndRails Europe Conference in Amsterdam.Recente Jobs
Bekijk alle jobs »»
Gereedschapskist
Onmisbare tools vooriedere developer!
- Ruby On Rails
Framework voor de web 2.0 developer. Eindelijk vooruitgang! - TextMate
Editor for true pro's
Typ, tab, top :-)
Nee, niet voor Win. - Made On A Mac
En nou is het over met die saaie grijze Windows bak van je!
Auteurs op deze site
Chris Obdam
'Less is more' evangelist, past dit ook dagelijks toe op zijn tandenborstel.Chiel Wester
Snelheidswonder op Ruby wielen. Leuk om mee te pair-programmen ;-)
Michael wo 28 jul 10 12:19
Hey Dax!
Maybe handy to have a boolean somewhere to hide and show the SQL queries? in development.rb or something.
Can imagine that you would like to see the sql queries the most of the times.
Michael
Plaats je reactie