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

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





Welkom op Holland On Rails

Het startpunt voor Ruby On Rails in Nederland. Vind de laatste technieken, meningen en nieuwtjes.

Recente Jobs

Gezocht: Ruby On Rails ontwikkelaar (junior of senior)

Eet, drink en droom jij over Ruby On Rails? Wil jij het liefste dag en nacht bezig zijn met jehobby; super coole webapplicaties ontwikkelen in Ruby On Rails?

Dan willen wij jou graag een podium bieden om je Ruby skills te vertonen aan onze nationale en internationale klanten!

@ Internetbureau Holder, Obdam

Bekijk alle jobs »»

Gereedschapskist

Onmisbare tools voor
iedere 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 ;-) Recommend Me
Src-120-attending

Stephan Kaag

Het eerste Rails coreteam- member uit Nederland? Rails evangelist van het eerste uur.

Paul Engel

Én Rails programmeren én interfaces designen? Je zou hem superman kunnen noemen..

Dax Huiberts

Official Zip-Programmer, skinny code is helemaal zijn ding. Haalt meer code weg dan dat er bij komt.

Freek Monteban

Het nieuwste telg uit het Holland on Rails nest! Hij doet niets anders meer!

Johan Vermeulen

De stylesheet-koning uit de kop van Noord-Holland!