How to Selectively Quite SQL Logging


#1

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


#2

Oops … should have been “quiet.”


#3

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

#4

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

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?