diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-01-13 18:30:48 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-01-13 19:00:45 +0100 |
commit | e0a521cfcd13e4d1f0ae8ab96004289e1c020f71 (patch) | |
tree | 3cfc6d031c0946bd1b669f5a17d60be8998955d6 | |
parent | 4f779e32d875209d917b01e4252ad34712178f26 (diff) | |
download | rails-e0a521cfcd13e4d1f0ae8ab96004289e1c020f71.tar.gz rails-e0a521cfcd13e4d1f0ae8ab96004289e1c020f71.tar.bz2 rails-e0a521cfcd13e4d1f0ae8ab96004289e1c020f71.zip |
Only lookup `config.log_level` for stdlib `::Logger`. Closes #11665.
This prevents Rails from assigning meaningless log levels to third
party loggers like log4r. If `Rails.logger` is not `kind_of?(::Logger)`
we simply assign the `config.log_level` as is.
This bug was introduced by #11665.
-rw-r--r-- | railties/CHANGELOG.md | 7 | ||||
-rw-r--r-- | railties/lib/rails/application/bootstrap.rb | 6 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 15 |
3 files changed, 26 insertions, 2 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index de3c1074ef..83747470bf 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,10 @@ +* Only lookup `config.log_level` for stdlib `::Logger` instances. + Assign it as is for third party loggers like `Log4r::Logger`. + + Fixes #13421. + + *Yves Senn* + * The `Gemfile` of new applications depends on SDoc ~> 0.4.0. *Xavier Noria* diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index a26d41c0cf..33bcab1e57 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -53,7 +53,11 @@ INFO logger end - Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase) + if ::Logger === Rails.logger + Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase) + else + Rails.logger.level = config.log_level + end end # Initialize cache early in the stack so railties can make use of it. diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 6158c416d7..02d8b2c91d 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -754,7 +754,7 @@ module ApplicationTests end end - test "config.log_level with custom logger" do + test "lookup config.log_level with custom logger (stdlib Logger)" do make_basic_app do |app| app.config.logger = Logger.new(STDOUT) app.config.log_level = :info @@ -762,6 +762,19 @@ module ApplicationTests assert_equal Logger::INFO, Rails.logger.level end + test "assign log_level as is with custom logger (third party logger)" do + logger_class = Class.new do + attr_accessor :level + end + logger_instance = logger_class.new + make_basic_app do |app| + app.config.logger = logger_instance + app.config.log_level = :info + end + assert_equal logger_instance, Rails.logger + assert_equal :info, Rails.logger.level + end + test "respond_to? accepts include_private" do make_basic_app |