# Rails logger.silence on controller action

**URL:** <https://www.ruby-forum.com/t/rails-logger-silence-on-controller-action/83113>\
**Category:** Rails\
**Created:** [January 23, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/rails-logger-silence-on-controller-action/83113 "2007-01-23T19:40:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 23, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/rails-logger-silence-on-controller-action/83113/1 "2007-01-23T19:40:46Z")

</div>

I’ve got a simple controller which is being hit every minute to monitor  
the website. I’ve read in a few places, and on this group as well that  
if you include a logger.silence around the code, it shouldn’t appear in  
the log. With the controller below, I get log entries every time the  
action is called. I’m just wondering what I may be doing wrong.

Thanks.

CONTROLLER:  
class MonitController \< ActionController::Base  
session :off

## this is used by the monitoring scripts to see if the mongrel is up

and running  
def index  
logger.silence do  
render :text =\> ‘success’  
end  
end  
end

LOG OUTPUT:  
Processing MonitController#index (for 127.0.0.1 at 2007-01-23 12:18:45)  
[GET]  
Parameters: {“action”=\>“index”, “controller”=\>“monit”}  
Completed in 0.00349 (286 reqs/sec) | Rendering: 0.00007 (2%) | DB:  
0.00000 (0%) | 200 OK [http:// /monit/index]

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 19, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/rails-logger-silence-on-controller-action/83113/2 "2007-03-19T22:37:29Z")

</div>

Just wondering if any solution was found for this - I’m in exactly the  
same position, looking to suppress Monit actions from appearing in my  
log. Wrapping the action in logger.silence seems to have no effect,  
nor does forcibly increasing the logger.level to try and filter it  
out.

I’m on Rails 1.1.6 - is it perhaps a 1.2+ thing only?

Cheers,  
Mike

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 20, 2007, 5:54am UTC](https://www.ruby-forum.com/t/rails-logger-silence-on-controller-action/83113/3 "2007-03-20T05:54:53Z")

</div>

Doesn’t appear to be (even in 1.2+), other than monkey patching  
ActionController::Base#log\_processing for your needs.

If you’re doing this to see if Mongrel is up, why not write a simple  
handler and place it in config/mongrel.conf? This won’t get logged  
anywhere, and is way faster than going to rails for it:

# lib/monit\_handler.rb

class MonitHandler \< Mongrel::HttpHandler  
def process(request, response)  
response.start { |head, out| out.write(“I’m up…”) }  
end  
end

# config/mongrel.conf

uri “/monit”, :handler =\> MonitHandler.new

Then in your production scripts, you need to pass in an extra switch  
to mongrel so it’ll use config/mongrel.conf. If you’re using mongrel  
cluster, add:

config\_script: config/mongrel.conf

to your config/mongrel\_cluster.yml

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 24, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/rails-logger-silence-on-controller-action/83113/4 "2007-03-24T22:15:57Z")

</div>

I did find a way around it. Putting a def logger end in the controller  
short circuits the logger from running and nothing is ever written to  
the log files. This has also had the added benefit of removing a large  
amount of memory usage for my application over time.

Also, I thought about going the mongrel handler route, but this works  
for now.

CONTROLLER:  
class MonitController \< ActionController::Base  
session :off

## this is used by the monitoring scripts to see if the mongrel is

up and running  
def index  
end  
def logger  
end  
end
