util: Fix crate name extraction for log_error_with_caller
(#35944)
The paths can be absolute, meaning they would just log the initial segment of where the repo was cloned. Release Notes: - N/A
This commit is contained in:
parent
8382afb2ba
commit
9cd5c3656e
1 changed files with 6 additions and 3 deletions
|
@ -669,9 +669,12 @@ where
|
||||||
let file = caller.file();
|
let file = caller.file();
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let file = caller.file().replace('\\', "/");
|
let file = caller.file().replace('\\', "/");
|
||||||
// In this codebase, the first segment of the file path is
|
// In this codebase all crates reside in a `crates` directory,
|
||||||
// the 'crates' folder, followed by the crate name.
|
// so discard the prefix up to that segment to find the crate name
|
||||||
let target = file.split('/').nth(1);
|
let target = file
|
||||||
|
.split_once("crates/")
|
||||||
|
.and_then(|(_, s)| s.split_once('/'))
|
||||||
|
.map(|(p, _)| p);
|
||||||
|
|
||||||
log::logger().log(
|
log::logger().log(
|
||||||
&log::Record::builder()
|
&log::Record::builder()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue