-
Notifications
You must be signed in to change notification settings - Fork 69
Enable subclasses to configure level isolation #103
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
Conversation
| Fiber.new do | ||
| assert_equal(logger.level, DEBUG) |
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.
This is mostly the same test as above, however, inside the Fiber the level does not get reset to INFO
|
This looks reasonable to me. @jeremyevans do you mind reviewing it too? |
jeremyevans
left a comment
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.
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]. |
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.
This looks wrong.
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.
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
|
I also approve with this change. |
(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
|
Thank you both so much for the quick review! |
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.