Feature Request: Add a (conditional) trait bound for Any to allow downcasting Log implementations #399
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log#399
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I need logging in the early stage of my program, before it can produce a proper configuration.
This means I wanted to add a
set_configfunction to my logging implementation (which is its own crate), that would replace the configuration stored behind aMutex<RefCell<Config>>in my logger.This would require downcasting the
&'static dyn Logobtained from theloggerfunction, which is not possible without adding a trait bound forAny.Anyis implemented for all types that ascribe to'static, which is all types thatlogcurrently accepts, that is&'static dyn LogandBox<dyn Log>.Therefore, this looks like a completely backwards compatible change (especially if feature-gated, either behind
stdor its ownanyfeature that requiresstd), and should be future proof too, as I don't think there's any way for log to support non-'static types.The only major issue would be that there is no easy way to have a conditional trait bound, short of either duplicating the trait definition with
cfg_if, or using a custom macro.Downcasting the installed logger does not seem required for this. You could alternatively e.g. provide a handle type that can update the configuration.
Ah! That would indeed work! Thank you.