Improve command logging and log_err module paths (#39674)

Prior we only logged the crate in `log_err`, which is not too helpful.
We now assemble the module path from the file system path.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-10-07 12:11:15 +00:00
committed by GitHub
parent 64eec67a81
commit 9a5034ea6d
10 changed files with 114 additions and 139 deletions
+6 -4
View File
@@ -605,13 +605,15 @@ where
// so discard the prefix up to that segment to find the crate name
let target = file
.split_once("crates/")
.and_then(|(_, s)| s.split_once('/'))
.map(|(p, _)| p);
.and_then(|(_, s)| s.split_once("/src/"));
let module_path = target.map(|(krate, module)| {
krate.to_owned() + "::" + &module.trim_end_matches(".rs").replace('/', "::")
});
log::logger().log(
&log::Record::builder()
.target(target.unwrap_or(""))
.module_path(target)
.target(target.map_or("", |(krate, _)| krate))
.module_path(module_path.as_deref())
.args(format_args!("{:?}", error))
.file(Some(caller.file()))
.line(Some(caller.line()))