Skip to content

Commit de39bdd

Browse files
committed
refactor: replace log with tracing in network debugging
1 parent e84cc17 commit de39bdd

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/cargo/util/network/http.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use curl::easy::Easy;
88
use curl::easy::InfoType;
99
use curl::easy::SslOpt;
1010
use curl::easy::SslVersion;
11-
use log::log;
12-
use log::Level;
11+
use tracing::debug;
12+
use tracing::trace;
1313

1414
use crate::util::config::SslVersionConfig;
1515
use crate::util::config::SslVersionConfigRange;
@@ -135,14 +135,19 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
135135

136136
if let Some(true) = http.debug {
137137
handle.verbose(true)?;
138-
log::debug!("{:#?}", curl::Version::get());
138+
tracing::debug!("{:#?}", curl::Version::get());
139139
handle.debug_function(|kind, data| {
140+
enum LogLevel {
141+
Debug,
142+
Trace,
143+
}
144+
use LogLevel::*;
140145
let (prefix, level) = match kind {
141-
InfoType::Text => ("*", Level::Debug),
142-
InfoType::HeaderIn => ("<", Level::Debug),
143-
InfoType::HeaderOut => (">", Level::Debug),
144-
InfoType::DataIn => ("{", Level::Trace),
145-
InfoType::DataOut => ("}", Level::Trace),
146+
InfoType::Text => ("*", Debug),
147+
InfoType::HeaderIn => ("<", Debug),
148+
InfoType::HeaderOut => (">", Debug),
149+
InfoType::DataIn => ("{", Trace),
150+
InfoType::DataOut => ("}", Trace),
146151
InfoType::SslDataIn | InfoType::SslDataOut => return,
147152
_ => return,
148153
};
@@ -159,16 +164,18 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
159164
} else if starts_with_ignore_case(line, "set-cookie") {
160165
line = "set-cookie: [REDACTED]";
161166
}
162-
log!(level, "http-debug: {} {}", prefix, line);
167+
match level {
168+
Debug => debug!("http-debug: {prefix} {line}"),
169+
Trace => trace!("http-debug: {prefix} {line}"),
170+
}
163171
}
164172
}
165173
Err(_) => {
166-
log!(
167-
level,
168-
"http-debug: {} ({} bytes of data)",
169-
prefix,
170-
data.len()
171-
);
174+
let len = data.len();
175+
match level {
176+
Debug => debug!("http-debug: {prefix} ({len} bytes of data)"),
177+
Trace => trace!("http-debug: {prefix} ({len} bytes of data)"),
178+
}
172179
}
173180
}
174181
})?;

0 commit comments

Comments
 (0)