Enable subclasses to configure level isolation#103
Merged
ioquatix merged 1 commit intoruby:masterfrom Nov 7, 2024
Merged
Conversation
skipkayhil
commented
Nov 6, 2024
Comment on lines
+79
to
+80
| Fiber.new do | ||
| assert_equal(logger.level, DEBUG) |
Contributor
Author
There was a problem hiding this comment.
This is mostly the same test as above, however, inside the Fiber the level does not get reset to INFO
Member
|
This looks reasonable to me. @jeremyevans do you mind reviewing it too? |
jeremyevans
suggested changes
Nov 6, 2024
Contributor
jeremyevans
left a comment
There was a problem hiding this comment.
I agree with the general idea. I found one change which seems to be an error. Once that is fixed, I think this is good to merge.
lib/logger.rb
Outdated
| # | ||
| # - A string suitable for use as a format for method | ||
| # {Time#strftime}[https://docs.ruby-lang.org/en/master/Time.html#method-i-strftime]. | ||
| # {Time#strftime}[level_key]. |
Contributor
Author
There was a problem hiding this comment.
Fixed! I should have reviewed the diff more closely 😅
`Logger#with_level` was recently added to enable configuring a `Logger`'s level for the duration of a block. However, the configured level is always tied to the currently running `Fiber`, which is not always ideal in applications that mix `Thread`s and `Fiber`s. For example, Active Support has provided a similar feature (`ActiveSupport::Logger#log_at`) which, depending on configuration, can be isolated to either `Thread`s or `Fiber`s. This commit enables subclasses of `Logger` to customize the level isolation. Ideally, it will enable replacing most of Active Support's `#log_at`, since both methods end up serving the same purpose.
d534fe6 to
8c9c928
Compare
jeremyevans
approved these changes
Nov 6, 2024
Open
4 tasks
Member
|
I also approve with this change. |
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Nov 7, 2024
(ruby/logger#103) `Logger#with_level` was recently added to enable configuring a `Logger`'s level for the duration of a block. However, the configured level is always tied to the currently running `Fiber`, which is not always ideal in applications that mix `Thread`s and `Fiber`s. For example, Active Support has provided a similar feature (`ActiveSupport::Logger#log_at`) which, depending on configuration, can be isolated to either `Thread`s or `Fiber`s. This commit enables subclasses of `Logger` to customize the level isolation. Ideally, it will enable replacing most of Active Support's `#log_at`, since both methods end up serving the same purpose. ruby/logger@dae2b832cd
Contributor
Author
|
Thank you both so much for the quick review! |
Open
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Logger#with_levelwas recently added to enable configuring aLogger's level for the duration of a block. However, the configured level is always tied to the currently runningFiber, which is not always ideal in applications that mixThreads andFibers.For example, Active Support has provided a similar feature (
ActiveSupport::Logger#log_at) which, depending on configuration, can be isolated to eitherThreads orFibers.This commit enables subclasses of
Loggerto customize the level isolation. Ideally, it will enable replacing most of Active Support's#log_at, since both methods end up serving the same purpose.