Use new-style format strings

This commit is contained in:
Matt Brubeck 2025-07-11 07:28:59 -07:00
parent dbc05d79c1
commit 738ab0adec
2 changed files with 19 additions and 23 deletions

View file

@ -73,7 +73,7 @@ fn main() {
panic!("Failed to listen on {addr}: {e}") panic!("Failed to listen on {addr}: {e}")
} else { } else {
// already listening on the other unspecified address // already listening on the other unspecified address
log::warn!("Could not start listener on {}, but already listening on another unspecified address. Probably your system automatically listens in dual stack?", addr); log::warn!("Could not start listener on {addr}, but already listening on another unspecified address. Probably your system automatically listens in dual stack?");
continue; continue;
} }
} }
@ -82,7 +82,7 @@ fn main() {
listening_unspecified |= addr.ip().is_unspecified(); listening_unspecified |= addr.ip().is_unspecified();
handles.push(tokio::spawn(async move { handles.push(tokio::spawn(async move {
log::info!("Started listener on {}", addr); log::info!("Started listener on {addr}");
loop { loop {
let (stream, _) = listener.accept().await.unwrap_or_else(|e| { let (stream, _) = listener.accept().await.unwrap_or_else(|e| {
@ -92,11 +92,11 @@ fn main() {
tokio::spawn(async { tokio::spawn(async {
match RequestHandle::new(stream, arc).await { match RequestHandle::new(stream, arc).await {
Ok(handle) => match handle.handle().await { Ok(handle) => match handle.handle().await {
Ok(info) => log::info!("{}", info), Ok(info) => log::info!("{info}"),
Err(err) => log::warn!("{}", err), Err(err) => log::warn!("{err}"),
}, },
Err(log_line) => { Err(log_line) => {
log::warn!("{}", log_line); log::warn!("{log_line}");
} }
} }
}); });
@ -134,11 +134,11 @@ fn main() {
tokio::spawn(async { tokio::spawn(async {
match RequestHandle::new_unix(stream, arc).await { match RequestHandle::new_unix(stream, arc).await {
Ok(handle) => match handle.handle().await { Ok(handle) => match handle.handle().await {
Ok(info) => log::info!("{}", info), Ok(info) => log::info!("{info}"),
Err(err) => log::warn!("{}", err), Err(err) => log::warn!("{err}"),
}, },
Err(log_line) => { Err(log_line) => {
log::warn!("{}", log_line); log::warn!("{log_line}");
} }
} }
}); });
@ -274,8 +274,7 @@ fn args() -> Result<Args> {
Err(_) => { Err(_) => {
// since certificate management should be automated, we are going to create the directory too // since certificate management should be automated, we are going to create the directory too
log::info!( log::info!(
"The certificate directory {:?} does not exist, creating it.", "The certificate directory {certs_path:?} does not exist, creating it."
certs_path
); );
std::fs::create_dir(&certs_path).expect("could not create certificate directory"); std::fs::create_dir(&certs_path).expect("could not create certificate directory");
// we just created the directory, skip loading from it // we just created the directory, skip loading from it
@ -295,7 +294,7 @@ fn args() -> Result<Args> {
// check if we have a certificate for that domain // check if we have a certificate for that domain
if let Host::Domain(ref domain) = hostname { if let Host::Domain(ref domain) = hostname {
if !matches!(certs, Some(ref certs) if certs.has_domain(domain)) { if !matches!(certs, Some(ref certs) if certs.has_domain(domain)) {
log::info!("No certificate or key found for {:?}, generating them.", s); log::info!("No certificate or key found for {s:?}, generating them.");
let mut cert_params = CertificateParams::new(vec![domain.clone()])?; let mut cert_params = CertificateParams::new(vec![domain.clone()])?;
cert_params cert_params
@ -496,7 +495,7 @@ impl RequestHandle<UnixStream> {
metadata, metadata,
}), }),
// use nonexistent status code 00 if connection was not established // use nonexistent status code 00 if connection was not established
Err(e) => Err(format!("{} \"\" 00 \"TLS error\" error:{}", log_line, e)), Err(e) => Err(format!("{log_line} \"\" 00 \"TLS error\" error:{e}")),
} }
} }
} }
@ -743,7 +742,7 @@ where
return Ok(()); return Ok(());
}; };
log::info!("Listing directory {:?}", path); log::info!("Listing directory {path:?}");
self.send_header(SUCCESS, "text/gemini").await?; self.send_header(SUCCESS, "text/gemini").await?;
self.stream.write_all(preamble.as_bytes()).await?; self.stream.write_all(preamble.as_bytes()).await?;

View file

@ -107,7 +107,7 @@ impl FileOptions {
/// (Re)reads a specified sidecar file. /// (Re)reads a specified sidecar file.
/// This function will allways try to read the file, even if it is current. /// This function will allways try to read the file, even if it is current.
fn read_database(&mut self, db: &Path) { fn read_database(&mut self, db: &Path) {
log::debug!("reading database {:?}", db); log::debug!("reading database {db:?}");
let mut ini = Ini::new_cs(); let mut ini = Ini::new_cs();
ini.set_default_section("mime"); ini.set_default_section("mime");
@ -124,7 +124,7 @@ impl FileOptions {
let files = match map { let files = match map {
Ok(section) => section, Ok(section) => section,
Err(err) => { Err(err) => {
log::error!("invalid config file {:?}: {}", db, err); log::error!("invalid config file {db:?}: {err}");
return; return;
} }
}; };
@ -147,8 +147,7 @@ impl FileOptions {
|| !header.chars().nth(2).unwrap().is_whitespace() || !header.chars().nth(2).unwrap().is_whitespace()
{ {
log::error!( log::error!(
"Line for {:?} starts like a full header line, but it is incorrect; ignoring it.", "Line for {path:?} starts like a full header line, but it is incorrect; ignoring it."
path
); );
return; return;
} }
@ -158,9 +157,7 @@ impl FileOptions {
// character has to be a space, so correct any // character has to be a space, so correct any
// other whitespace to it (e.g. tabs) // other whitespace to it (e.g. tabs)
log::warn!( log::warn!(
"Full Header line for {:?} has an invalid character, treating {:?} as a space.", "Full Header line for {path:?} has an invalid character, treating {separator:?} as a space."
path,
separator
); );
} }
let status = header let status = header
@ -193,12 +190,12 @@ impl FileOptions {
match glob_with(path, glob_options) { match glob_with(path, glob_options) {
Ok(paths) => paths.collect::<Vec<_>>(), Ok(paths) => paths.collect::<Vec<_>>(),
Err(err) => { Err(err) => {
log::error!("incorrect glob pattern in {:?}: {}", path, err); log::error!("incorrect glob pattern in {path:?}: {err}");
continue; continue;
} }
} }
} else { } else {
log::error!("path is not UTF-8: {:?}", path); log::error!("path is not UTF-8: {path:?}");
continue; continue;
}; };
@ -213,7 +210,7 @@ impl FileOptions {
self.file_meta.insert(path, preset.clone()); self.file_meta.insert(path, preset.clone());
} }
Err(err) => { Err(err) => {
log::warn!("could not process glob path: {}", err); log::warn!("could not process glob path: {err}");
continue; continue;
} }
}; };