Clear level overrides in #dup and #clone - #137
Conversation
This allows fiber keys to be GCed and removed from the map. Otherwise, fibers that call `#with_level` create a memory leak if they are killed without running their ensure blocks.
Cloning loggers can be used, for example, to create different loggers for different classes/components/subsystems that share the same log_dev and other configuration (possibly a subclass of Logger), but with different verbosity levels, formatters, etc. But, that doesn't work if they share `@level_override`. Rather than use OverrideMap.new, the existing `@level_override` is cloned and cleared, to preserve `@level_override`'s class.
5f37f2b to
1b4e472
Compare
|
I re-verified this copy-isolation change against Logger 1.7.0/current and found one adjacent internal object that remains shared: @default_formatter. Mutating the copy's default formatter configuration can therefore affect the original, while explicit custom formatters should continue to be shared by caller choice. I prepared a one-line follow-up directly on this PR head: OskarEichler@08d2055 It duplicates only Logger's internal default formatter inside the existing initialize_copy hook. The release/current suites pass on Ruby 4.0.6 and 3.2.11, and the focused copy model verifies isolated internal formatter state while explicit custom formatter identity remains shared. No repository tests were changed. I kept this on #137's lineage to preserve the original ownership point and avoid a competing PR. |
Cloning loggers can be used, for example, to create different loggers for different classes/components/subsystems that share the same log_dev and other configuration (possibly a subclass of Logger), but with different verbosity levels, formatters, etc.
But, that can break if they share
@level_override. Rather than use OverrideMap.new, the existing@level_overrideis cloned and cleared, to preserve@level_override's class.This PR is based on #136 to avoid merge conflicts. But it can be updated to be independent of that other PR, if so desired.