2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2017-10-21 09:11:29 -04:00
|
|
|
require "active_support/concern"
|
|
|
|
require "active_support/core_ext/module/attribute_accessors"
|
2018-10-02 17:02:27 -04:00
|
|
|
require "active_support/logger_thread_safe_level"
|
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
|
2018-10-01 18:00:18 -04:00
|
|
|
ActiveSupport::Deprecation.warn(
|
|
|
|
"Including LoggerSilence is deprecated and will be removed in Rails 6.1. " \
|
|
|
|
"Please use `ActiveSupport::LoggerSilence` instead"
|
|
|
|
)
|
|
|
|
|
|
|
|
include ActiveSupport::LoggerSilence
|
2012-12-21 13:35:10 -05:00
|
|
|
end
|
2018-10-01 18:00:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module ActiveSupport
|
|
|
|
module LoggerSilence
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
cattr_accessor :silencer, default: true
|
2018-10-02 17:02:27 -04:00
|
|
|
include ActiveSupport::LoggerThreadSafeLevel
|
2018-10-01 18:00:18 -04:00
|
|
|
end
|
2012-12-21 13:35:10 -05:00
|
|
|
|
2018-10-01 18:00:18 -04:00
|
|
|
# Silences the logger for the duration of the block.
|
|
|
|
def silence(temporary_level = Logger::ERROR)
|
|
|
|
if silencer
|
|
|
|
begin
|
|
|
|
old_local_level = local_level
|
|
|
|
self.local_level = temporary_level
|
2015-06-09 22:38:53 -04:00
|
|
|
|
2018-10-01 18:00:18 -04:00
|
|
|
yield self
|
|
|
|
ensure
|
|
|
|
self.local_level = old_local_level
|
|
|
|
end
|
|
|
|
else
|
2012-12-21 13:35:10 -05:00
|
|
|
yield self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-11 15:00:51 -05:00
|
|
|
end
|