refactor(updater): replace `log` crate with `tracing` for improved logging

pull/2592/head
thepoy 4 months ago
parent efe3f88acd
commit f1860531d2
No known key found for this signature in database
GPG Key ID: 7F560817AF7B0601

2
Cargo.lock generated

@ -6975,7 +6975,6 @@ dependencies = [
"futures-util", "futures-util",
"http", "http",
"infer", "infer",
"log",
"minisign-verify", "minisign-verify",
"osakit", "osakit",
"percent-encoding", "percent-encoding",
@ -6990,6 +6989,7 @@ dependencies = [
"thiserror 2.0.9", "thiserror 2.0.9",
"time", "time",
"tokio", "tokio",
"tracing",
"url", "url",
"windows-sys 0.59.0", "windows-sys 0.59.0",
"zip", "zip",

@ -30,7 +30,7 @@ tauri = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
log = { workspace = true } tracing = { workspace = true }
tokio = "1" tokio = "1"
reqwest = { version = "0.12", default-features = false, features = [ reqwest = { version = "0.12", default-features = false, features = [
"json", "json",

@ -387,14 +387,14 @@ impl Updater {
.replace("{{arch}}", self.arch) .replace("{{arch}}", self.arch)
.parse()?; .parse()?;
log::debug!("checking for updates {url}"); tracing::debug!("checking for updates {url}");
let mut request = ClientBuilder::new().user_agent(UPDATER_USER_AGENT); let mut request = ClientBuilder::new().user_agent(UPDATER_USER_AGENT);
if let Some(timeout) = self.timeout { if let Some(timeout) = self.timeout {
request = request.timeout(timeout); request = request.timeout(timeout);
} }
if let Some(ref proxy) = self.proxy { if let Some(ref proxy) = self.proxy {
log::debug!("using proxy {proxy}"); tracing::debug!("using proxy {proxy}");
let proxy = reqwest::Proxy::all(proxy.as_str())?; let proxy = reqwest::Proxy::all(proxy.as_str())?;
request = request.proxy(proxy); request = request.proxy(proxy);
} }
@ -415,36 +415,36 @@ impl Updater {
if res.status().is_success() { if res.status().is_success() {
// no updates found! // no updates found!
if StatusCode::NO_CONTENT == res.status() { if StatusCode::NO_CONTENT == res.status() {
log::debug!("update endpoint returned 204 No Content"); tracing::debug!("update endpoint returned 204 No Content");
return Ok(None); return Ok(None);
}; };
let update_response: serde_json::Value = res.json().await?; let update_response: serde_json::Value = res.json().await?;
log::debug!("update response: {update_response:?}"); tracing::debug!("update response: {update_response:?}");
raw_json = Some(update_response.clone()); raw_json = Some(update_response.clone());
match serde_json::from_value::<RemoteRelease>(update_response) match serde_json::from_value::<RemoteRelease>(update_response)
.map_err(Into::into) .map_err(Into::into)
{ {
Ok(release) => { Ok(release) => {
log::debug!("parsed release response {release:?}"); tracing::debug!("parsed release response {release:?}");
last_error = None; last_error = None;
remote_release = Some(release); remote_release = Some(release);
// we found a release, break the loop // we found a release, break the loop
break; break;
} }
Err(err) => { Err(err) => {
log::error!("failed to deserialize update response: {err}"); tracing::error!("failed to deserialize update response: {err}");
last_error = Some(err) last_error = Some(err)
} }
} }
} else { } else {
log::error!( tracing::error!(
"update endpoint did not respond with a successful status code" "update endpoint did not respond with a successful status code"
); );
} }
} }
Err(err) => { Err(err) => {
log::error!("failed to check for updates: {err}"); tracing::error!("failed to check for updates: {err}");
last_error = Some(err.into()) last_error = Some(err.into())
} }
} }
@ -713,7 +713,7 @@ impl Update {
}; };
if let Some(on_before_exit) = self.on_before_exit.as_ref() { if let Some(on_before_exit) = self.on_before_exit.as_ref() {
log::debug!("running on_before_exit hook"); tracing::debug!("running on_before_exit hook");
on_before_exit(); on_before_exit();
} }
@ -882,7 +882,7 @@ impl Update {
#[cfg(feature = "zip")] #[cfg(feature = "zip")]
if infer::archive::is_gz(bytes) { if infer::archive::is_gz(bytes) {
log::debug!("extracting AppImage"); tracing::debug!("extracting AppImage");
// extract the buffer to the tmp_dir // extract the buffer to the tmp_dir
// we extract our signed archive into our final directory without any temp file // we extract our signed archive into our final directory without any temp file
let archive = Cursor::new(bytes); let archive = Cursor::new(bytes);
@ -906,7 +906,7 @@ impl Update {
return Err(Error::BinaryNotFoundInArchive); return Err(Error::BinaryNotFoundInArchive);
} }
log::debug!("rewriting AppImage"); tracing::debug!("rewriting AppImage");
return match std::fs::write(&self.extract_path, bytes) return match std::fs::write(&self.extract_path, bytes)
.and_then(|_| std::fs::set_permissions(&self.extract_path, permissions)) .and_then(|_| std::fs::set_permissions(&self.extract_path, permissions))
{ {
@ -960,7 +960,7 @@ impl Update {
fn install_deb(&self, bytes: &[u8]) -> Result<()> { fn install_deb(&self, bytes: &[u8]) -> Result<()> {
// First verify the bytes are actually a .deb package // First verify the bytes are actually a .deb package
if !infer::archive::is_deb(bytes) { if !infer::archive::is_deb(bytes) {
log::warn!("update is not a valid deb package"); tracing::warn!("update is not a valid deb package");
return Err(Error::InvalidUpdaterFormat); return Err(Error::InvalidUpdaterFormat);
} }
@ -1003,7 +1003,7 @@ impl Update {
.status() .status()
{ {
if status.success() { if status.success() {
log::debug!("installed deb with pkexec"); tracing::debug!("installed deb with pkexec");
return Ok(()); return Ok(());
} }
} }
@ -1011,7 +1011,7 @@ impl Update {
// 2. Try zenity or kdialog for a graphical sudo experience // 2. Try zenity or kdialog for a graphical sudo experience
if let Ok(password) = self.get_password_graphically() { if let Ok(password) = self.get_password_graphically() {
if self.install_with_sudo(deb_path, &password)? { if self.install_with_sudo(deb_path, &password)? {
log::debug!("installed deb with GUI sudo"); tracing::debug!("installed deb with GUI sudo");
return Ok(()); return Ok(());
} }
} }
@ -1024,7 +1024,7 @@ impl Update {
.status()?; .status()?;
if status.success() { if status.success() {
log::debug!("installed deb with sudo"); tracing::debug!("installed deb with sudo");
Ok(()) Ok(())
} else { } else {
Err(Error::DebInstallFailed) Err(Error::DebInstallFailed)
@ -1148,7 +1148,7 @@ impl Update {
}; };
if need_authorization { if need_authorization {
log::debug!("app installation needs admin privileges"); tracing::debug!("app installation needs admin privileges");
// Use AppleScript to perform moves with admin privileges // Use AppleScript to perform moves with admin privileges
let apple_script = format!( let apple_script = format!(
"do shell script \"rm -rf '{src}' && mv -f '{new}' '{src}'\" with administrator privileges", "do shell script \"rm -rf '{src}' && mv -f '{new}' '{src}'\" with administrator privileges",

Loading…
Cancel
Save