-
Notifications
You must be signed in to change notification settings - Fork 58
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
Enable subclasses to configure level isolation #103
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? |
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
@@ -426,7 +426,7 @@ def with_level(severity) | |||
# Argument +datetime_format+ should be either of these: | |||
# | |||
# - 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_level
was 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 mixThread
s andFiber
s.For example, Active Support has provided a similar feature (
ActiveSupport::Logger#log_at
) which, depending on configuration, can be isolated to eitherThread
s orFiber
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.