1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/lib/active_support/logger_silence.rb
Edouard CHIN 783f86822b Deprecate the LoggerSilence constant:
- I found this weird that the LoggerSilence wasn't using the
  `ActiveSupport` namespace (AFAIK all other classes have it).

  This PR deprecate the use of `LoggerSilence` for
  `ActiveSupport::LoggerSilence` instead.
2018-10-02 12:59:04 -04:00

43 lines
977 B
Ruby

# frozen_string_literal: true
require "active_support/concern"
require "active_support/core_ext/module/attribute_accessors"
module LoggerSilence
extend ActiveSupport::Concern
included do
ActiveSupport::Deprecation.warn(
"Including LoggerSilence is deprecated and will be removed in Rails 6.1. " \
"Please use `ActiveSupport::LoggerSilence` instead"
)
include ActiveSupport::LoggerSilence
end
end
module ActiveSupport
module LoggerSilence
extend ActiveSupport::Concern
included do
cattr_accessor :silencer, default: true
end
# 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
yield self
ensure
self.local_level = old_local_level
end
else
yield self
end
end
end
end