Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2 silence logging deprecation warning

In Rails 3.2 I get deprecation warning, when using logger.silence {}. In release note: "ActiveSupport::BufferedLogger#silence is deprecated. If you want to squelch logs for a certain block, change the log level for that block."

How I can easily change log level for the block?

like image 666
Mikhail K. Avatar asked Jan 31 '12 08:01

Mikhail K.


2 Answers

It appears that logger.silence is being replaced by simply silence:

logger.silence do
    #your silenced code here
end

becomes:

silence do
    #your silenced code here
end

At least it doesn't generate the depreciation warning anymore, and it does silence the logged output.

like image 164
user1132534 Avatar answered Oct 19 '22 10:10

user1132534


The first answer is good, but not complete. We were having issues trying to figure this one out too. silence &block has been deprecated in Rails 3, so you should use the updated syntax calling the logger directly:

Rails.logger.silence do
  # your code here...
end

For even more sweet, sweet customizability, you can pass a log level to #silence().

like image 22
Dan Avatar answered Oct 19 '22 10:10

Dan