Level/Context override storage
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
Direção de pesquisa
Leia #132, #136 e #137 primeiro; em seguida, rastreie Logger#initialize e os pontos de entrada #with_level e #with_context. Compare a API proposta de ContextStore com o armazenamento atual de sobrescritas e resolva o comportamento de herança de Fiber. Considera-se concluído quando o armazenamento de contexto compartilhado personalizável funcionar sem criar uma subclasse de Logger e o comportamento de sobrescrita existente continuar coberto.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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).
- Linguagem predominante
- Ruby
- Estrelas
- 161
- Forks
- 76
- Merge médio
- 2d 5h
- PRs com merge (30d)
- 3
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de ruby/logger
-
Programs using Logger sometimes resist SIGTERM / SIGINTTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Later writes fail with "closed stream" when renaming the log fails during rotation on WindowsAberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 52/100
-
`datetime_format=` does not apply to custom formattersTalvez já em andamento @Rubyist007 assumiu há 229 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
Todas as issues de ruby/logger
Issues semelhantes
-
SecureRandom.alphanumeric can silently return an empty or wrong-length secret instead of raisingAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
ruby/securerandom#92 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
open-feature/ruby-sdk-contrib#340 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
zold-io/wts.zold.io#651 ·
Mantenedores costumam responder em até 1 dia
-
good first issue help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 87/100
erkamyaman/rust-anything#788 ·
Mantenedores costumam responder em até 1 dia