# How to Selectively Quite SQL Logging

**URL:** <https://www.ruby-forum.com/t/how-to-selectively-quite-sql-logging/102387>\
**Category:** Rails\
**Created:** [January 12, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/how-to-selectively-quite-sql-logging/102387 "2006-01-12T22:54:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [January 12, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/how-to-selectively-quite-sql-logging/102387/1 "2006-01-12T22:54:07Z")

</div>

I know about logger.silence but here is the issue: I’m comfortable with  
the way the user engine is working, but it generates quite a bit of SQL  
noise in the logs. I’d like, for that engine, to suppress the SQL  
logging.

Code in it has return statements in conditionals, e.g.,

```
if !user?
  RAILS_DEFAULT_LOGGER.debug "checking guest authorisation for 

```

#{controller}/#{action}"  
if User.guest\_user\_authorized?(controller, action)  
yield block if block != nil  
return true  
end  
else  
RAILS\_DEFAULT\_LOGGER.debug “checking user:#{session[:user].id}  
authorisation for #{controller}/#{action}”  
if current\_user.authorized?(controller, action)  
yield block if block != nil  
return true  
end  
end  
return false

so… bracketing it in logger.silence do blocks may cause the logger to  
remain off if the early out return statement is executed.

Suggestions for leaving SQL logging on for the app in general but off  
for the user engine?

Thanks

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [January 12, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/how-to-selectively-quite-sql-logging/102387/2 "2006-01-12T22:54:57Z")

</div>

Oops … should have been “quiet.”

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [January 12, 2006, 11:01pm UTC](https://www.ruby-forum.com/t/how-to-selectively-quite-sql-logging/102387/3 "2006-01-12T23:01:36Z")

</div>

If your logger level is set above debug, you shouldn’t see the  
messages output in the fragment you’ve posted… does that sound like  
a reasonable solution? There is a fair peppering of the user engine  
(and engines plugin) code at the moment with logger statements, so I  
do appreciate the issue.

- james

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [January 13, 2006, 12:32am UTC](https://www.ruby-forum.com/t/how-to-selectively-quite-sql-logging/102387/4 "2006-01-13T00:32:50Z")

</div>

Setting the logger level above debug would be fine, except there’s a  
fair peppering of logger statements in _my_ code as well 🙂

I figured if it was easy, it would have been done. This is a problem not  
just for engines, but also for plugins and components. It would be cool  
if there were some hook that allowed for logging levels to be adjusted  
before and after some of these things. Hmmmmm… I wonder whether an  
around\_filter might work?
