# Disable Logging on a Controller/Action

**URL:** <https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236>\
**Category:** rubyonrails-talk\
**Created:** [April 27, 2010, 6:05pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236 "2010-04-27T18:05:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom10](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@Tom10](https://discuss.rubyonrails.org/u/Tom10)\
**Post date:** [April 27, 2010, 6:05pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236/1 "2010-04-27T18:05:56Z")

</div>

Does anyone know what the best way to disable logging on a controller or specific action? I've seen a lot of threads, but no real "best practice"?

Thanks, Tom

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [April 27, 2010, 6:43pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236/2 "2010-04-27T18:43:06Z")

</div>

TomRossi7 wrote:

> Does anyone know what the best way to disable logging on a controller or specific action? I've seen a lot of threads, but no real "best practice"?

Why would you ever want to do this? An inaccurate log is worse than none at all.

What's your use case?

> Thanks, Tom

Best,

---

<div class="post-metadata">

**Author:** ![Tom10](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@Tom10](https://discuss.rubyonrails.org/u/Tom10)\
**Post date:** [April 27, 2010, 7:02pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236/3 "2010-04-27T19:02:23Z")

</div>

I have an action being called by a monitoring service.

Leaving this out of the log is not "inaccurate", anymore than not logging static files referenced is the public folder is "inaccurate".

Thanks, Tom

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [April 27, 2010, 9:08pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236/4 "2010-04-27T21:08:29Z")

</div>

TomRossi7 wrote:

> I have an action being called by a monitoring service.
> 
> Leaving this out of the log is not "inaccurate",

I'm not sure I agree. The log tells you what Rails has been up to. One of the things it has been up to is servicing the requests that come from the monitoring service. Leaving those requests out of the log will lessen the utility of the log.

Consider: if there were a bug or bottleneck in the monitoring request, how would you know? If the monitoring service weren't requesting its action, how would you know?

Picking and choosing in the log is a bad idea.

> anymore than not logging static files referenced is the public folder is "inaccurate".

The analogy doesn't hold. The log is specifically a Rails log. Files in /public aren't served by Rails; therefore, they don't appear in the log. Your monitoring requests, however, are served by Rails and should appear in the log.

> Thanks, Tom

Best,

---

<div class="post-metadata">

**Author:** ![Tom10](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@Tom10](https://discuss.rubyonrails.org/u/Tom10)\
**Post date:** [April 27, 2010, 10:49pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236/5 "2010-04-27T22:49:47Z")

</div>

Marnen,

I do appreciate the feedback, but I wonder if others agree? Maybe that is why its not a simple task within Rails?

Anyone?

Thanks, Tom

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [April 27, 2010, 11:45pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236/6 "2010-04-27T23:45:43Z")

</div>

I think logging is a tool, and what you choose to record is up to you.

That said, I have no idea how to selectively turn off the standard Rails logging. 🙂

I was able to get rid of the usual "Processing blah blah..." message with e.g.

&nbsp;&nbsp;def index &nbsp;&nbsp;&nbsp;&nbsp;logger.auto\_flushing= 0 &nbsp;&nbsp;&nbsp;&nbsp;@things = Thing.all &nbsp;&nbsp;&nbsp;&nbsp;logger.send("clear\_buffer") &nbsp;&nbsp;&nbsp;&nbsp;logger.auto\_flushing= 1000 &nbsp;&nbsp;end

but the "Rendering template blah blah... " still shows up. Maybe that'll give you some ideas. Sounds like a good idea for a gem, if selective (or more configurable) logging isn't part of Rails 3. I haven't looked.

FWIW,

---

<div class="post-metadata">

**Author:** ![Jeff\_Burly](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jeff\_Burly](https://discuss.rubyonrails.org/u/Jeff_Burly)\
**Post date:** [April 27, 2010, 11:54pm UTC](https://discuss.rubyonrails.org/t/disable-logging-on-a-controller-action/51236/7 "2010-04-27T23:54:10Z")

</div>

Hi Tom,

Not sure if it applies to your specific case, but whenever I come across the need to quiet the logging activity for some particular verbose-under-normal-logging activity process that I'm really only concerned about logging-wise only if it fails, ... I usually just temporarily up the log-level for the specific handling of that process. Something like:

&nbsp;&nbsp;# in the controller: &nbsp;&nbsp;... &nbsp;&nbsp;bak\_log\_level = logger.level &nbsp;&nbsp;begin &nbsp;&nbsp;&nbsp;&nbsp;logger.level = Logger::ERROR &nbsp;&nbsp;&nbsp;&nbsp;# do some stuff ... &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;ensure &nbsp;&nbsp;&nbsp;&nbsp;logger.level = bak\_log\_level &nbsp;&nbsp;end &nbsp;&nbsp;...

Jeff
