zlog: Add env var to enable line number logging (#41905)

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-11-06 15:31:26 +00:00
committed by GitHub
parent 9c8e37a156
commit 6f6f652cf2
4 changed files with 30 additions and 10 deletions
+10 -6
View File
@@ -611,17 +611,21 @@ where
let file = caller.file().replace('\\', "/");
// In this codebase all crates reside in a `crates` directory,
// 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("/src/"));
let file = file.split_once("crates/");
let target = file.as_ref().and_then(|(_, s)| s.split_once("/src/"));
let module_path = target.map(|(krate, module)| {
krate.to_owned() + "::" + &module.trim_end_matches(".rs").replace('/', "::")
if module.starts_with(krate) {
module.trim_end_matches(".rs").replace('/', "::")
} else {
krate.to_owned() + "::" + &module.trim_end_matches(".rs").replace('/', "::")
}
});
let file = file.map(|(_, file)| format!("crates/{file}"));
log::logger().log(
&log::Record::builder()
.target(target.map_or("", |(krate, _)| krate))
.module_path(module_path.as_deref())
.target(module_path.as_deref().unwrap_or(""))
.module_path(file.as_deref())
.args(format_args!("{:?}", error))
.file(Some(caller.file()))
.line(Some(caller.line()))