Skip to content

Commit 5522091

Browse files
committed
Auto merge of #12582 - ehuss:network-target, r=epage
Set tracing target for networking messages. This changes the log messages for messages related to network traffic to use the "network" tracing target. This makes it easier to do `CARGO_LOG=network=trace CARGO_HTTP_DEBUG=true` instead of trying to figure out which modules to include (and to avoid `CARGO_LOG=trace` which can be too noisy). For example, #12290 moved the location of some log messages to a different module, which broke the documented workflow of using `CARGO_LOG=cargo::ops::registry=debug` to get networking information.
2 parents e05e43a + f0176a1 commit 5522091

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

src/cargo/core/package.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
712712
// happen during `wait_for_download`
713713
let token = self.next;
714714
self.next += 1;
715-
debug!("downloading {} as {}", id, token);
715+
debug!(target: "network", "downloading {} as {}", id, token);
716716
assert!(self.pending_ids.insert(id));
717717

718718
let (mut handle, _timeout) = http_handle_and_timeout(self.set.config)?;
@@ -731,7 +731,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
731731
crate::try_old_curl_http2_pipewait!(self.set.multiplexing, handle);
732732

733733
handle.write_function(move |buf| {
734-
debug!("{} - {} bytes of data", token, buf.len());
734+
debug!(target: "network", "{} - {} bytes of data", token, buf.len());
735735
tls::with(|downloads| {
736736
if let Some(downloads) = downloads {
737737
downloads.pending[&token]
@@ -812,7 +812,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
812812
let (dl, data) = loop {
813813
assert_eq!(self.pending.len(), self.pending_ids.len());
814814
let (token, result) = self.wait_for_curl()?;
815-
debug!("{} finished with {:?}", token, result);
815+
debug!(target: "network", "{} finished with {:?}", token, result);
816816

817817
let (mut dl, handle) = self
818818
.pending
@@ -873,7 +873,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
873873
return Err(e.context(format!("failed to download from `{}`", dl.url)))
874874
}
875875
RetryResult::Retry(sleep) => {
876-
debug!("download retry {} for {sleep}ms", dl.url);
876+
debug!(target: "network", "download retry {} for {sleep}ms", dl.url);
877877
self.sleeping.push(sleep, (dl, handle));
878878
}
879879
}
@@ -969,7 +969,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
969969
.perform()
970970
.with_context(|| "failed to perform http requests")
971971
})?;
972-
debug!("handles remaining: {}", n);
972+
debug!(target: "network", "handles remaining: {}", n);
973973
let results = &mut self.results;
974974
let pending = &self.pending;
975975
self.set.multi.messages(|msg| {
@@ -978,7 +978,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
978978
if let Some(result) = msg.result_for(handle) {
979979
results.push((token, result));
980980
} else {
981-
debug!("message without a result (?)");
981+
debug!(target: "network", "message without a result (?)");
982982
}
983983
});
984984

@@ -988,7 +988,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
988988
assert_ne!(self.remaining(), 0);
989989
if self.pending.is_empty() {
990990
let delay = self.sleeping.time_to_next().unwrap();
991-
debug!("sleeping main thread for {delay:?}");
991+
debug!(target: "network", "sleeping main thread for {delay:?}");
992992
std::thread::sleep(delay);
993993
} else {
994994
let min_timeout = Duration::new(1, 0);

src/cargo/sources/registry/http_remote.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl<'cfg> HttpRegistry<'cfg> {
335335
}),
336336
RetryResult::Err(e) => Err(e),
337337
RetryResult::Retry(sleep) => {
338-
debug!("download retry {:?} for {sleep}ms", download.path);
338+
debug!(target: "network", "download retry {:?} for {sleep}ms", download.path);
339339
self.downloads.sleeping.push(sleep, (download, handle));
340340
continue;
341341
}
@@ -551,7 +551,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
551551
&& path == Path::new(RegistryConfig::NAME)
552552
&& self.config.cli_unstable().registry_auth =>
553553
{
554-
debug!("re-attempting request for config.json with authorization included.");
554+
debug!(target: "network", "re-attempting request for config.json with authorization included.");
555555
self.fresh.remove(path);
556556
self.auth_required = true;
557557

@@ -568,9 +568,11 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
568568
}
569569
}
570570
Ok(challenge) => {
571-
debug!("ignoring non-Cargo challenge: {}", challenge.scheme)
571+
debug!(target: "network", "ignoring non-Cargo challenge: {}", challenge.scheme)
572+
}
573+
Err(e) => {
574+
debug!(target: "network", "failed to parse challenge: {}", e)
572575
}
573-
Err(e) => debug!("failed to parse challenge: {}", e),
574576
}
575577
}
576578
}
@@ -618,7 +620,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
618620

619621
let mut handle = http_handle(self.config)?;
620622
let full_url = self.full_url(path);
621-
debug!("fetch {}", full_url);
623+
debug!(target: "network", "fetch {}", full_url);
622624
handle.get(true)?;
623625
handle.url(&full_url)?;
624626
handle.follow_location(true)?;
@@ -653,7 +655,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
653655
self.auth_error_headers.clone(),
654656
)?;
655657
headers.append(&format!("Authorization: {}", authorization))?;
656-
trace!("including authorization for {}", full_url);
658+
trace!(target: "network", "including authorization for {}", full_url);
657659
}
658660
handle.http_headers(headers)?;
659661

@@ -662,7 +664,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
662664
// We do that through this token. Each request (and associated response) gets one.
663665
let token = self.downloads.next;
664666
self.downloads.next += 1;
665-
debug!("downloading {} as {}", path.display(), token);
667+
debug!(target: "network", "downloading {} as {}", path.display(), token);
666668
let is_new = self.downloads.pending_paths.insert(path.to_path_buf());
667669
assert!(is_new, "path queued for download more than once");
668670

@@ -671,7 +673,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
671673
// That thread-local is set up in `block_until_ready` when it calls self.multi.perform,
672674
// which is what ultimately calls this method.
673675
handle.write_function(move |buf| {
674-
trace!("{} - {} bytes of data", token, buf.len());
676+
trace!(target: "network", "{} - {} bytes of data", token, buf.len());
675677
tls::with(|downloads| {
676678
if let Some(downloads) = downloads {
677679
downloads.pending[&token]
@@ -772,7 +774,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
772774
}
773775

774776
fn block_until_ready(&mut self) -> CargoResult<()> {
775-
trace!(
777+
trace!(target: "network",
776778
"block_until_ready: {} transfers pending",
777779
self.downloads.pending.len()
778780
);
@@ -787,15 +789,15 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
787789
.perform()
788790
.with_context(|| "failed to perform http requests")
789791
})?;
790-
trace!("{} transfers remaining", remaining_in_multi);
792+
trace!(target: "network", "{} transfers remaining", remaining_in_multi);
791793

792794
if remaining_in_multi + self.downloads.sleeping.len() as u32 == 0 {
793795
return Ok(());
794796
}
795797

796798
if self.downloads.pending.is_empty() {
797799
let delay = self.downloads.sleeping.time_to_next().unwrap();
798-
debug!("sleeping main thread for {delay:?}");
800+
debug!(target: "network", "sleeping main thread for {delay:?}");
799801
std::thread::sleep(delay);
800802
} else {
801803
// We have no more replies to provide the caller with,

src/cargo/util/network/http.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
135135

136136
if let Some(true) = http.debug {
137137
handle.verbose(true)?;
138-
tracing::debug!("{:#?}", curl::Version::get());
138+
tracing::debug!(target: "network", "{:#?}", curl::Version::get());
139139
handle.debug_function(|kind, data| {
140140
enum LogLevel {
141141
Debug,
@@ -167,16 +167,20 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
167167
line = "set-cookie: [REDACTED]";
168168
}
169169
match level {
170-
Debug => debug!("http-debug: {prefix} {line}"),
171-
Trace => trace!("http-debug: {prefix} {line}"),
170+
Debug => debug!(target: "network", "http-debug: {prefix} {line}"),
171+
Trace => trace!(target: "network", "http-debug: {prefix} {line}"),
172172
}
173173
}
174174
}
175175
Err(_) => {
176176
let len = data.len();
177177
match level {
178-
Debug => debug!("http-debug: {prefix} ({len} bytes of data)"),
179-
Trace => trace!("http-debug: {prefix} ({len} bytes of data)"),
178+
Debug => {
179+
debug!(target: "network", "http-debug: {prefix} ({len} bytes of data)")
180+
}
181+
Trace => {
182+
trace!(target: "network", "http-debug: {prefix} ({len} bytes of data)")
183+
}
180184
}
181185
}
182186
}

src/cargo/util/network/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ macro_rules! try_old_curl {
2929
let result = $e;
3030
if cfg!(target_os = "macos") {
3131
if let Err(e) = result {
32-
::tracing::warn!("ignoring libcurl {} error: {}", $msg, e);
32+
::tracing::warn!(target: "network", "ignoring libcurl {} error: {}", $msg, e);
3333
}
3434
} else {
3535
use ::anyhow::Context;

src/doc/contrib/src/implementation/debugging.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CARGO_LOG=debug cargo generate-lockfile
1616
CARGO_LOG=cargo::core::resolver=trace cargo generate-lockfile
1717

1818
# This will print lots of info about the download process. `trace` prints even more.
19-
CARGO_HTTP_DEBUG=true CARGO_LOG=cargo::ops::registry=debug cargo fetch
19+
CARGO_HTTP_DEBUG=true CARGO_LOG=network=debug cargo fetch
2020

2121
# This is an important command for diagnosing fingerprint issues.
2222
CARGO_LOG=cargo::core::compiler::fingerprint=trace cargo build

src/doc/src/reference/config.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ crate dependencies and accessing remote git repositories.
622622
* Environment: `CARGO_HTTP_DEBUG`
623623

624624
If `true`, enables debugging of HTTP requests. The debug information can be
625-
seen by setting the `CARGO_LOG=cargo::ops::registry=debug` environment
626-
variable (or use `trace` for even more information).
625+
seen by setting the `CARGO_LOG=network=debug` environment
626+
variable (or use `network=trace` for even more information).
627627

628628
Be wary when posting logs from this output in a public location. The output
629629
may include headers with authentication tokens which you don't want to leak!

0 commit comments

Comments
 (0)