Skip to content

Clear level overrides in #dup and #clone#137

Open
nevans wants to merge 2 commits into
ruby:masterfrom
nevans:clone-resets-logger_override
Open

Clear level overrides in #dup and #clone#137
nevans wants to merge 2 commits into
ruby:masterfrom
nevans:clone-resets-logger_override

Conversation

@nevans

@nevans nevans commented Oct 1, 2025

Copy link
Copy Markdown

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_override is 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.

nevans added 2 commits October 1, 2025 12:16
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.
@nevans nevans force-pushed the clone-resets-logger_override branch from 5f37f2b to 1b4e472 Compare October 1, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant