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?
            Asked
            
        
        
            Active
            
        
            Viewed 1,459 times
        
    3
            
            
         
    
    
        Paul
        
- 25,812
- 38
- 124
- 247
2 Answers
6
            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
 
    
    
        Community
        
- 1
- 1
 
    
    
        Richard Peck
        
- 76,116
- 9
- 93
- 147
2
            
            
        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...
 
    
    
        pixelearth
        
- 13,674
- 10
- 62
- 110