2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2017-06-30 01:00:04 -04:00
|
|
|
require_relative "concern"
|
|
|
|
require_relative "core_ext/module/attribute_accessors"
|
2016-08-06 11:58:50 -04:00
|
|
|
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
|
2017-05-31 05:16:20 -04:00
|
|
|
cattr_accessor :silencer, default: true
|
2012-12-21 13:35:10 -05:00
|
|
|
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
|