Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveSupport::LogSubscriber restore compatibility with SemanticLogger #49621

Merged

Conversation

casperisfine
Copy link
Contributor

Fix: #49563

The semantic_logger gems doesn't behave exactly like stdlib logger in that SemanticLogger#level returns a Symbol while stdlib Logger#level returns an Integer.

Because of this we can't simply compare integers, we have to use the various #{level}? methods.

Fix: rails#49563

The semantic_logger gems doesn't behave exactly like stdlib logger
in that `SemanticLogger#level` returns a Symbol while stdlib `Logger#level`
returns an Integer.

Because of this we can't simply compare integers, we have to use the
various `#{level}?` methods.
@byroot byroot merged commit c9da269 into rails:main Oct 13, 2023
3 of 4 checks passed
byroot added a commit that referenced this pull request Oct 13, 2023
…-compatibility

ActiveSupport::LogSubscriber restore compatibility with SemanticLogger
@preethi29
Copy link

@byroot Facing the same issue related to log level. Which version can we expect this fix to be available?

@byroot
Copy link
Member

byroot commented Oct 31, 2023

You can fix it right now by pointing your Gemfile at 7-0-stable.

@preethi29
Copy link

preethi29 commented Oct 31, 2023

@byroot I started facing this issue when I tried to upgrade from 7.0.8 to 7.1.1. Should I be pointing to 7-0-stable or 7-1-stable?

Will this change be released in a new version called 7.1.2?

@zzak
Copy link
Member

zzak commented Nov 4, 2023

@preethi29 I think he meant 7-1-stable since this bug doesn't affect 7.0

@byroot
Copy link
Member

byroot commented Nov 4, 2023

Yeah that's what I meant, sorry.

Edouard-chin added a commit to Edouard-chin/rails that referenced this pull request Dec 12, 2023
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 rails#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 rails#50324
Edouard-chin added a commit to Edouard-chin/rails that referenced this pull request Dec 12, 2023
- ### 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 rails#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 rails#50324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants