Advertencia de desaprobación del registro de silencio de Rails 3.2

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?

preguntado el 31 de enero de 12 a las 08:01

4 Respuestas

Parece que logger.silence is being replaced by simply silence:

logger.silence do
    #your silenced code here

se convierte en:

silence do
    #your silenced code here

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

Respondido el 21 de Septiembre de 12 a las 11:09

silence should have one argument, shouldn't it?… - kuboon

This doesn't work at all in Rails 3.2.x and kuboon is correct in that plain 'silence' needs an argument. - astjohn

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...

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

Respondido 22 Jul 13, 22:07

def silent_method
  old_level = Rails.logger.level
  Rails.logger.level = 7

  result = your_code_here

  Rails.logger.level = old_level


Respondido 11 Feb 12, 02:02

Or quietly{}, Desde silence requires a stream.

respondido 31 mar '15, 18:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.