Feature Request: downcasting Log, but for real #666
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#666
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?
Seems #399 was already closed (4.5 years ago, for bad usecase & maybe backwards compatibility reasons?), but I have an actual use!
My logger writes a message on panic, but does so with a custom format different to anything you can write with the
Logtrait. So I need to be able to downcast the&dyn Loginto my own logger from the panic handler. I could probably use aOnceLockto store if my logger's been initialized butlogalready does that with the (set_)loggermethods, so it feels redundant.For now my current way of doing this is this very cursed set of functions:
but that's a lot of unsafe, and nightly-only.
To prevent needing to add a
+ 'staticbound onLog(which probably breaks compatibility somehow), yandros suggested (in rplcs #dark-arts) adding something like:as an automatic implementation on the
Logtrait.Hi @1e1001 👋
This is something I'd be open to exploring a bit more. We'd need to be careful adding a
type_idmethod to theLogtrait, because it would be unsound to override. TheErrortrait for instance defines its squirrel-type-id method like this to try get around thatAh yeah that makes sense, in which case I'm not quite sure how one would implement that without some sort of
+ 'staticor+ Anybound on theLogtrait itself (although I'm curious on how much real code that would actually break, given that the library only ever asks for&'static dyn Logs).I am the author of indicatif-log-bridge and i would like the same feature, downcasting the
&'static dyn Logto LogWrapper (the specific logger) to access the interalMultiProgress.i might be misinformed but i think this would be as simple as adding a simple function with a default implementation to Log
due to the default implementation it would be backwards compatible.