Level/Context override storage
還沒有人認領這個 Issue。
評估
研究方向
先閱讀 #132、#136 和 #137,然後追蹤 Logger#initialize 以及 #with_level 和 #with_context 進入點。將提議的 ContextStore API 與目前的覆寫儲存進行比較,並釐清 Fiber 的繼承行為。完成的標準是:無需繼承 Logger 即可使用可自訂的共用情境儲存,且現有的覆寫行為仍受到涵蓋。
由索引模型根據 Issue 內容生成。
描述
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).
- 主要語言
- Ruby
- 星號
- 161
- 分支
- 76
- 平均合併
- 2 天 5 小時
- 30 天內合併 PR
- 3
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ruby/logger 的其他 Issue
-
Programs using Logger sometimes resist SIGTERM / SIGINT可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
-
難度 3/5 1-2 天 新手友好度 68/100
-
難度 4/5 3-5 天 新手友好度 48/100
-
難度 3/5 1-2 天 新手友好度 52/100
-
`datetime_format=` does not apply to custom formatters可能已有人在做 @Rubyist007 於 229 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 72/100
相似的 Issue
-
SecureRandom.alphanumeric can silently return an empty or wrong-length secret instead of raising未關閉
難度 2/5 1-3 小時 新手友好度 67/100
ruby/securerandom#92 ·
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
open-feature/ruby-sdk-contrib#340 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
zold-io/wts.zold.io#651 ·
維護者通常 1 天內回覆
-
good first issue help wanted
難度 2/5 1-3 小時 新手友好度 87/100
erkamyaman/rust-anything#788 ·
維護者通常 1 天內回覆