2016-08-06 11:58:50 -04:00
|
|
|
require "active_support/concern"
|
|
|
|
require "active_support/core_ext/module/attribute_accessors"
|
|
|
|
require "concurrent"
|
2012-12-21 13:35:10 -05:00
|
|
|
|
|
|
|
module LoggerSilence
|
|
|
|
extend ActiveSupport::Concern
|
2015-12-14 17:27:03 -05:00
|
|
|
|
2012-12-21 13:35:10 -05:00
|
|
|
included do
|
|
|
|
cattr_accessor :silencer
|
|
|
|
self.silencer = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Silences the logger for the duration of the block.
|
|
|
|
def silence(temporary_level = Logger::ERROR)
|
|
|
|
if silencer
|
|
|
|
begin
|
2016-02-11 15:00:51 -05:00
|
|
|
old_local_level = local_level
|
|
|
|
self.local_level = temporary_level
|
2015-06-09 22:38:53 -04:00
|
|
|
|
2012-12-21 13:35:10 -05:00
|
|
|
yield self
|
|
|
|
ensure
|
2016-02-11 15:00:51 -05:00
|
|
|
self.local_level = old_local_level
|
2012-12-21 13:35:10 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
yield self
|
|
|
|
end
|
|
|
|
end
|
2016-02-11 15:00:51 -05:00
|
|
|
end
|