log
log copied to clipboard
Use `std::panic::Location` for file & line information
this commit adds a feature, track_caller, that allows the user to opt-in to using location information from std::panic::Location instead of the built-in file! and line! macros. This will allow log record location information to be manipulated in the same way that #[track_caller] allows panic location information to be manipulated
Is there a benefit to doing this?
Ah, sorry didn't see the second part of your comment, ignore my previous comment.
It allows you to manipulate location information for log messages in the same way that you can for panic! messages. For example, one of my applications has a generic "retry-er" that takes a closure and a retry policy, and will run the closure until it gets a successful return value from the closure or until it hits it's max retries. Currently, any logging we do from the retryer (like "got error Foo, retry 1/10") will include location information from inside the retryer, but no identifying information about exactly which closure generated the error. Of course, we could simply pass more information to the retryer to help us identify the piece of code that is erroring out, but I thought it would be possible to use #[track_caller] for this instead, to keep the API cleaner. Turns out I couldn't use log::error!, log::warn!, etc, because those macros use file!() and line!(). I can do it if I write my own log::Record-generating code, but I thought having this functionality built-in to log might be useful for others.
r? @sfackler @jdm
My earlier concern has been addressed, but otherwise I'm just a bystander :)
no problem, thanks!
bump, can someone take a look at this?
Just coming in through some triage. I think the only outstanding thing here was using our build script to automatically use track_caller if we're on at least 1.46.0.