Level/Context override storage
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Trước tiên, hãy đọc #132, #136 và #137, sau đó lần theo Logger#initialize cùng các điểm vào #with_level và #with_context. So sánh API ContextStore được đề xuất với cơ chế lưu trữ override hiện tại và xác định hành vi kế thừa của Fiber. Hoàn thành khi cơ chế lưu trữ ngữ cảnh dùng chung có thể tùy chỉnh hoạt động mà không cần tạo lớp con của Logger và hành vi override hiện có vẫn được bao phủ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I submitted a couple of PRs that solve the basic problems I have with the current level overrides:
- #136
- #137
But I'd prefer to change it a bit more.
If #132 (or something like it) is accepted:
- I believe that the "fiber scoped" block overrides for both
#with_leveland#with_contextshould use the same storage strategy. Rather than keeping two separate maps, I think it's better to combine them into a shared strategy:@override_storeor@context_store. - To share storage with a hash-like API, that suggests that
level_keyandcontext_keyneed to have different values. We could use something likeFiber[:logger_level_key] ||= Object.new, to support bothHashandObjectSpace::WeakKeyMap, but that's kinda gross.
The current approach doesn't allow us to cleanly swap in the Fiber-storage API:
- Fiber doesn't implement
#delete - We can't reset storage with
clone.clear(which is what I used in #137).
Fiber storage does face the additional question of how to handle when fibers aren't nested in a "structured concurrency" manner: does the child continue with its inherited storage after the parent leaves the #with_level or #with_context block. I think yes, it should... but others may want different behavior.
And many applications, frameworks, or libraries will already have their own encapsulation of execution context, which may not be identical to Fiber.current. As an example of this, see ActiveSupport::IsolatedExecutionState, which is used by the ActiveSupport::LoggerThreadSafeLevel mixin.
All these concerns can be addressed by creating a simple API, creating a default class that implements that API, and allowing an instance to be passed in as an argument to #initialize.
I propose something like the following:
class Logger
class ContextStore
def initialize
@levels = ObjectSpace::WeakKeyMap.new
end
def level_override = @levels[Fiber.current]
def level_override=(val) @levels[Fiber.current] = val end
def clear = @levels.clear
private
def initialize_copy(original)
super
@levels = @levels.dup
end
end
def initialize(*, context_store: nil, **)
# ...
@context_store = context_store || ContextStore.new
# ...
end
end
This mimics the current implementation, with the addition of #136 and #137.
The benefits of this approach:
- This allows users to customize context storage implementation without subclassing Logger.
- By encapsulating all execution state context, we can remove implementation details (like
#level_key) from theLoggerclass. - This simplifies using Fiber.storage for inheritance of logger context.
- This can easily be extended to use the same strategy for both level overrides and context (see e.g: #132).
- Ngôn ngữ chính
- Ruby
- Star
- 161
- Fork
- 76
- Merge trung bình
- 2 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ruby/logger
-
Programs using Logger sometimes resist SIGTERM / SIGINTCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Later writes fail with "closed stream" when renaming the log fails during rotation on WindowsĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
`datetime_format=` does not apply to custom formattersCó thể đã có người làm @Rubyist007 đã nhận 229 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
open-feature/ruby-sdk-contrib#340 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zold-io/wts.zold.io#651 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
erkamyaman/rust-anything#788 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
TheOdinProject/curriculum#31579 ·
Maintainer thường phản hồi trong vòng 1 ngày