Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
config.log_level
being ignored when using a Broadcast Logger:
- ### Problem If an application has configured a Broadcast Logger, setting the `config.log_level` to any value has no effect: ```ruby # config/application.rb config.logger = ActiveSupport::BroadcastLogger.new(Logger.new(STDOUT)) config.log_level = :warn puts Rails.logger.broadcasts.map(&:level) # => [Logger::DEBUG] ``` This is a side effect of #49621 which tried to fix the `log_level` default value overriding the whole broadcasts. ### Context The `log_level` default's value shouldn't apply to a Broadcast Logger, as otherwise it overrides whatever the application previously configured. While this behaviour is the same with a vanilla logger, at least we can workaround it: ```ruby # When using a vanilla logger config.logger = Logger.new(STDOUT, level: LOGGER::WARN) # Once the app boots, the level is overriden to DEBUG. We need to add the following line. config.log_level = :warn # When using a broadcast logger stdout = Logger.new(STDOUT, level: Logger::INFO) stderr = Logger.new(STDERR, level: Logger::ERROR) config.logger = ActiveSupport::BroadcastLogger(stdout, stderr) # Once the app boots the whole broadcast level is overriden to DEBUG. # There is no way to workaround this as you can't fine grain the level of each # loggers with `config.log_level=`. ``` ### Solution This PR ignores the default `log_level` value when using a Broadcast Logger, but ensure it gets used if an application manually sets it. Fix #50324
- Loading branch information