examples: Log line numbers in the transfer example (#4485)

## Description

This makes reading logfiles so much more pleasant.

## Breaking Changes

This is an example: none.

## Notes & open questions

n/a

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All breaking changes documented.
- [x] This PR was created by a human that thought critically about the
      proposed change and wrote an as clear and concise description as
      they could.
- [x] This PR isn't slop, and is carefully crafted to do have the
      intented effect.
This commit is contained in:
Floris Bruynooghe
2026-08-26 13:28:59 +00:00
committed by GitHub
parent 55e1d7bb41
commit 3677ec6210
+5 -5
View File
@@ -1346,18 +1346,18 @@ mod duration_micros {
}
pub fn init_tracing(path: Option<&Path>) {
use tracing_subscriber::{fmt, registry};
let layer = tracing_subscriber::fmt::layer().with_line_number(true);
if let Some(path) = path {
let file = File::create(path).expect("failed to create trace log file");
let filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new("iroh=trace,transfer=trace,noq=trace"));
let layer = fmt::layer().with_writer(file).with_filter(filter);
registry().with(layer).init()
let layer = layer.with_writer(file).with_filter(filter);
tracing_subscriber::registry().with(layer).init()
} else {
let layer = fmt::layer()
let layer = layer
.with_writer(std::io::stderr)
.with_filter(EnvFilter::from_default_env());
registry().with(layer).init()
tracing_subscriber::registry().with(layer).init()
}
}