mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-29 12:38:02 +00:00
Add file and line number information to logs (#2568)
This PR adds codegen from rustc to track the file and line number of calls to `log_err()`. I haven't noticed much longer compile times on my machine, and looking at the [implementation](https://rustc-dev-guide.rust-lang.org/backend/implicit-caller-location.html) it essentially adds an extra argument and secret reference pass. However, this will show a lot more data in our logs on user machines. Requesting review from @ForLoveOfCats, who usually knows a bunch about this kind of thing :)
This commit is contained in:
commit
5e4da6433f
1 changed files with 4 additions and 1 deletions
|
@ -9,6 +9,7 @@ pub mod test;
|
|||
use std::{
|
||||
cmp::{self, Ordering},
|
||||
ops::{AddAssign, Range, RangeInclusive},
|
||||
panic::Location,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
@ -129,11 +130,13 @@ where
|
|||
{
|
||||
type Ok = T;
|
||||
|
||||
#[track_caller]
|
||||
fn log_err(self) -> Option<T> {
|
||||
match self {
|
||||
Ok(value) => Some(value),
|
||||
Err(error) => {
|
||||
log::error!("{:?}", error);
|
||||
let caller = Location::caller();
|
||||
log::error!("{}:{}: {:?}", caller.file(), caller.line(), error);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue