Forum: Ruby on Rails How to Selectively Quite SQL Logging

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Steve R. (Guest)
on 2006-01-12 23:54
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

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

    if !user?
      RAILS_DEFAULT_LOGGER.debug "checking guest authorisation for
      if User.guest_user_authorized?(controller, action)
        yield block if block != nil
        return true
      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
    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?

Steve R. (Guest)
on 2006-01-12 23:54
Oops ... should have been "quiet."
James A. (Guest)
on 2006-01-13 00:01
(Received via mailing list)
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
Steve R. (Guest)
on 2006-01-13 01:32
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?
This topic is locked and can not be replied to.