-
-
Notifications
You must be signed in to change notification settings - Fork 128
Respect action_dispatch.log_rescued_responses #266
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
base: master
Are you sure you want to change the base?
Respect action_dispatch.log_rescued_responses #266
Conversation
This is a new configuration option in Rails 7 which defaults to true. When an app sets this to false, this method does not log anything at all for rescued responses. Because rails_semantic_logger monkey patches ActionDispatch::DebugExceptions and overrides this method, this configuration option does not have any effect. Let's correct that. More context on this configuration option: - PR which introduced it rails/rails#42592 - Evidence that this implementation should work fine in Rails 7.1+ https://github.com/rails/rails/blob/v7.1.0/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L137 I also noticed that rails_semantic_logger is not respecting the action_dispatch.debug_exception_log_level configuration, and it makes its own decisions about what is an appropriate level. I updated this to also follow that configuration. This is also how it works in Rails 7.1+: https://github.com/rails/rails/blob/v7.1.0/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L154
Rails.application.deprecators.silence do | ||
level = wrapper.respond_to?(:rescue_response?) && wrapper.rescue_response? ? :debug : :fatal | ||
return if !log_rescued_responses?(request) && wrapper.rescue_response? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #179, there was a concern about the rescue_responses?
method not working in Rails 5 and 6, which led to this respond_to?
check being added. I don't believe it's necessary, however, because this is within a conditional that checks (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 7
, so we can feel confident that we are in Rails 7.1+. Given that, I took the liberty of removing the respond_to?
check
level = wrapper.respond_to?(:rescue_response?) && wrapper.rescue_response? ? :debug : :fatal | ||
return if !log_rescued_responses?(request) && wrapper.rescue_response? | ||
|
||
level = request.get_header("action_dispatch.debug_exception_log_level") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this more aligned with the default behavior of ActionDispatch::DebugExceptions
makes sense to me. I don't think this is a breaking change, because the previous behavior was merged to the master branch, but never released. Let me know if you'd like me to remove this part though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This PR is iterating a bit on #179
Description of changes
action_dispatch.log_rescued_responses is a new configuration option in Rails 7 which defaults to true. When an app sets this to false, this method does not log anything at all for rescued responses.
Because rails_semantic_logger monkey patches
ActionDispatch::DebugExceptions and overrides this method, this configuration option does not have any effect. Let's correct that.
More context on this configuration option:
rescue_responses
rails/rails#42592I also noticed that rails_semantic_logger is not respecting the action_dispatch.debug_exception_log_level configuration, and it makes its own decisions about what is an appropriate level. I updated this to also follow that configuration.
This is also how it works in Rails 7.1+:
https://github.com/rails/rails/blob/v7.1.0/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L154
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.