mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Deprecate ActiveSupport::Benchmarkable#silence.
Due to its lack of thread safety, we're deprecating this, and it will be removed in Rails 4.1. Fixes #4060.
This commit is contained in:
parent
bb732beba7
commit
ed2fea908a
3 changed files with 23 additions and 12 deletions
|
@ -1619,26 +1619,32 @@ class BasicsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_silence_sets_log_level_to_error_in_block
|
def test_silence_sets_log_level_to_error_in_block
|
||||||
original_logger = ActiveRecord::Base.logger
|
original_logger = ActiveRecord::Base.logger
|
||||||
log = StringIO.new
|
|
||||||
ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
|
assert_deprecated do
|
||||||
ActiveRecord::Base.logger.level = Logger::DEBUG
|
log = StringIO.new
|
||||||
ActiveRecord::Base.silence do
|
ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
|
||||||
ActiveRecord::Base.logger.warn "warn"
|
ActiveRecord::Base.logger.level = Logger::DEBUG
|
||||||
ActiveRecord::Base.logger.error "error"
|
ActiveRecord::Base.silence do
|
||||||
|
ActiveRecord::Base.logger.warn "warn"
|
||||||
|
ActiveRecord::Base.logger.error "error"
|
||||||
|
end
|
||||||
|
assert_equal "error\n", log.string
|
||||||
end
|
end
|
||||||
assert_equal "error\n", log.string
|
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.logger = original_logger
|
ActiveRecord::Base.logger = original_logger
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_silence_sets_log_level_back_to_level_before_yield
|
def test_silence_sets_log_level_back_to_level_before_yield
|
||||||
original_logger = ActiveRecord::Base.logger
|
original_logger = ActiveRecord::Base.logger
|
||||||
log = StringIO.new
|
|
||||||
ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
|
assert_deprecated do
|
||||||
ActiveRecord::Base.logger.level = Logger::WARN
|
log = StringIO.new
|
||||||
ActiveRecord::Base.silence do
|
ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
|
||||||
|
ActiveRecord::Base.logger.level = Logger::WARN
|
||||||
|
ActiveRecord::Base.silence do
|
||||||
|
end
|
||||||
|
assert_equal Logger::WARN, ActiveRecord::Base.logger.level
|
||||||
end
|
end
|
||||||
assert_equal Logger::WARN, ActiveRecord::Base.logger.level
|
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.logger = original_logger
|
ActiveRecord::Base.logger = original_logger
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
## Rails 4.0.0 (unreleased) ##
|
## Rails 4.0.0 (unreleased) ##
|
||||||
|
|
||||||
|
* ActiveSupport::Benchmarkable#silence has been deprecated due to its lack of
|
||||||
|
thread safety. It will be removed without replacement in Rails 4.1. *Steve
|
||||||
|
Klabnik*
|
||||||
|
|
||||||
* An optional block can be passed to `Hash#deep_merge`. The block will be invoked for each duplicated key
|
* An optional block can be passed to `Hash#deep_merge`. The block will be invoked for each duplicated key
|
||||||
and used to resolve the conflict. *Pranas Kiziela*
|
and used to resolve the conflict. *Pranas Kiziela*
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ module ActiveSupport
|
||||||
# Silence the logger during the execution of the block.
|
# Silence the logger during the execution of the block.
|
||||||
#
|
#
|
||||||
def silence
|
def silence
|
||||||
|
ActiveSupport::Deprecation.warn "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1."
|
||||||
old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger
|
old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
|
|
Loading…
Reference in a new issue