I know that Rails logging could be suppressed for entire controller using the silencer gem. But could an SQL output of some ActiveRecord request be suppressed individually by wrapping it into some statements?
Silence
I don't have a specific answer for your question, but we use ActiveRecord::Base.logger.silence to silence the logger:
ActiveRecord::Base.logger.silence do
# your method here
end
It's not for specific requests, but works for actions you may wish to stop logging. Perhaps you could extend ActiveRecord::Base to silence a specific method?
--
Extending ActiveRecord
Perhaps you could mix what I've described with extending ActiveRecord? The recommendation on this question is to use an ActiveRecord concern.
I've never used one of these - can put together some code if you feel applicable
I use this:
save_for_later = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil #turns off sql activity
... do stuff...
ActiveRecord::Base.logger = save_for_later
I've never done this in production code btw, only in rake tasks...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With