Skip to content

Commit d407712

Browse files
committed
refactor(updater): replace tracing with log for conditional logging
1 parent 4fcda36 commit d407712

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

.changes/updater-logging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"updater": patch
33
---
44

5-
replace log crate with tracing for improved logging.
5+
replace tracing with log for conditional logging.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/updater/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ tauri = { workspace = true }
3030
serde = { workspace = true }
3131
serde_json = { workspace = true }
3232
thiserror = { workspace = true }
33-
tracing = { workspace = true }
33+
log = { workspace = true }
34+
tracing = { workspace = true, optional = true }
3435
tokio = "1"
3536
reqwest = { version = "0.12", default-features = false, features = [
3637
"json",
@@ -71,3 +72,4 @@ zip = ["dep:zip", "dep:tar", "dep:flate2"]
7172
native-tls = ["reqwest/native-tls"]
7273
native-tls-vendored = ["reqwest/native-tls-vendored"]
7374
rustls-tls = ["reqwest/rustls-tls"]
75+
tracing = ["dep:tracing"]

plugins/updater/src/updater.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use std::ffi::OsStr;
1818
use base64::Engine;
1919
use futures_util::StreamExt;
2020
use http::HeaderName;
21+
#[cfg(not(feature = "tracing"))]
22+
use log as logger;
2123
use minisign_verify::{PublicKey, Signature};
2224
use percent_encoding::{AsciiSet, CONTROLS};
2325
use reqwest::{
@@ -28,6 +30,8 @@ use semver::Version;
2830
use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize};
2931
use tauri::{utils::platform::current_exe, AppHandle, Resource, Runtime};
3032
use time::OffsetDateTime;
33+
#[cfg(feature = "tracing")]
34+
use tracing as logger;
3135
use url::Url;
3236

3337
use crate::{
@@ -387,14 +391,14 @@ impl Updater {
387391
.replace("{{arch}}", self.arch)
388392
.parse()?;
389393

390-
tracing::debug!("checking for updates {url}");
394+
logger::debug!("checking for updates {url}");
391395

392396
let mut request = ClientBuilder::new().user_agent(UPDATER_USER_AGENT);
393397
if let Some(timeout) = self.timeout {
394398
request = request.timeout(timeout);
395399
}
396400
if let Some(ref proxy) = self.proxy {
397-
tracing::debug!("using proxy {proxy}");
401+
logger::debug!("using proxy {proxy}");
398402
let proxy = reqwest::Proxy::all(proxy.as_str())?;
399403
request = request.proxy(proxy);
400404
}
@@ -415,36 +419,36 @@ impl Updater {
415419
if res.status().is_success() {
416420
// no updates found!
417421
if StatusCode::NO_CONTENT == res.status() {
418-
tracing::debug!("update endpoint returned 204 No Content");
422+
logger::debug!("update endpoint returned 204 No Content");
419423
return Ok(None);
420424
};
421425

422426
let update_response: serde_json::Value = res.json().await?;
423-
tracing::debug!("update response: {update_response:?}");
427+
logger::debug!("update response: {update_response:?}");
424428
raw_json = Some(update_response.clone());
425429
match serde_json::from_value::<RemoteRelease>(update_response)
426430
.map_err(Into::into)
427431
{
428432
Ok(release) => {
429-
tracing::debug!("parsed release response {release:?}");
433+
logger::debug!("parsed release response {release:?}");
430434
last_error = None;
431435
remote_release = Some(release);
432436
// we found a release, break the loop
433437
break;
434438
}
435439
Err(err) => {
436-
tracing::error!("failed to deserialize update response: {err}");
440+
logger::error!("failed to deserialize update response: {err}");
437441
last_error = Some(err)
438442
}
439443
}
440444
} else {
441-
tracing::error!(
445+
logger::error!(
442446
"update endpoint did not respond with a successful status code"
443447
);
444448
}
445449
}
446450
Err(err) => {
447-
tracing::error!("failed to check for updates: {err}");
451+
logger::error!("failed to check for updates: {err}");
448452
last_error = Some(err.into())
449453
}
450454
}
@@ -713,7 +717,7 @@ impl Update {
713717
};
714718

715719
if let Some(on_before_exit) = self.on_before_exit.as_ref() {
716-
tracing::debug!("running on_before_exit hook");
720+
logger::debug!("running on_before_exit hook");
717721
on_before_exit();
718722
}
719723

@@ -882,7 +886,7 @@ impl Update {
882886

883887
#[cfg(feature = "zip")]
884888
if infer::archive::is_gz(bytes) {
885-
tracing::debug!("extracting AppImage");
889+
logger::debug!("extracting AppImage");
886890
// extract the buffer to the tmp_dir
887891
// we extract our signed archive into our final directory without any temp file
888892
let archive = Cursor::new(bytes);
@@ -906,7 +910,7 @@ impl Update {
906910
return Err(Error::BinaryNotFoundInArchive);
907911
}
908912

909-
tracing::debug!("rewriting AppImage");
913+
logger::debug!("rewriting AppImage");
910914
return match std::fs::write(&self.extract_path, bytes)
911915
.and_then(|_| std::fs::set_permissions(&self.extract_path, permissions))
912916
{
@@ -960,7 +964,7 @@ impl Update {
960964
fn install_deb(&self, bytes: &[u8]) -> Result<()> {
961965
// First verify the bytes are actually a .deb package
962966
if !infer::archive::is_deb(bytes) {
963-
tracing::warn!("update is not a valid deb package");
967+
logger::warn!("update is not a valid deb package");
964968
return Err(Error::InvalidUpdaterFormat);
965969
}
966970

@@ -1003,15 +1007,15 @@ impl Update {
10031007
.status()
10041008
{
10051009
if status.success() {
1006-
tracing::debug!("installed deb with pkexec");
1010+
logger::debug!("installed deb with pkexec");
10071011
return Ok(());
10081012
}
10091013
}
10101014

10111015
// 2. Try zenity or kdialog for a graphical sudo experience
10121016
if let Ok(password) = self.get_password_graphically() {
10131017
if self.install_with_sudo(deb_path, &password)? {
1014-
tracing::debug!("installed deb with GUI sudo");
1018+
logger::debug!("installed deb with GUI sudo");
10151019
return Ok(());
10161020
}
10171021
}
@@ -1024,7 +1028,7 @@ impl Update {
10241028
.status()?;
10251029

10261030
if status.success() {
1027-
tracing::debug!("installed deb with sudo");
1031+
logger::debug!("installed deb with sudo");
10281032
Ok(())
10291033
} else {
10301034
Err(Error::DebInstallFailed)
@@ -1148,7 +1152,7 @@ impl Update {
11481152
};
11491153

11501154
if need_authorization {
1151-
tracing::debug!("app installation needs admin privileges");
1155+
logger::debug!("app installation needs admin privileges");
11521156
// Use AppleScript to perform moves with admin privileges
11531157
let apple_script = format!(
11541158
"do shell script \"rm -rf '{src}' && mv -f '{new}' '{src}'\" with administrator privileges",

0 commit comments

Comments
 (0)