Skip to content

Commit 9aa0d6e

Browse files
authored
chore: remove unstable log features & use qualified log::<macro> path (#9069)
* chore: remove unstable log features & use qualified `log::<macro>` path * fmt * fix build
1 parent 46de49a commit 9aa0d6e

37 files changed

Lines changed: 147 additions & 173 deletions

File tree

.changes/utils-debug-eprintln.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': 'major:breaking'
3+
---
4+
5+
Removed `debug_eprintln!` and `consume_unused_variable` macros.

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.

core/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ raw-window-handle = "0.6"
2121
http = "0.2"
2222
url = "2"
2323
tracing = { version = "0.1", optional = true }
24+
log = "0.4"
2425

2526
[target."cfg(windows)".dependencies]
2627
webview2-com = "0.28"

core/tauri-runtime-wry/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use tao::{
5959
};
6060
#[cfg(target_os = "macos")]
6161
use tauri_utils::TitleBarStyle;
62-
use tauri_utils::{config::WindowConfig, debug_eprintln, Theme};
62+
use tauri_utils::{config::WindowConfig, Theme};
6363
use url::Url;
6464
use wry::{
6565
FileDropEvent as WryFileDropEvent, ProxyConfig, ProxyEndpoint, WebContext, WebView,
@@ -2808,14 +2808,14 @@ fn handle_user_message<T: UserEvent>(
28082808
WebviewMessage::EvaluateScript(script, tx, span) => {
28092809
let _span = span.entered();
28102810
if let Err(e) = webview.evaluate_script(&script) {
2811-
debug_eprintln!("{}", e);
2811+
log::error!("{}", e);
28122812
}
28132813
tx.send(()).unwrap();
28142814
}
28152815
#[cfg(not(all(feature = "tracing", not(target_os = "android"))))]
28162816
WebviewMessage::EvaluateScript(script) => {
28172817
if let Err(e) = webview.evaluate_script(&script) {
2818-
debug_eprintln!("{}", e);
2818+
log::error!("{}", e);
28192819
}
28202820
}
28212821
WebviewMessage::Navigate(url) => webview.load_url(url.as_str()),
@@ -2964,7 +2964,7 @@ fn handle_user_message<T: UserEvent>(
29642964
});
29652965
}
29662966
Err(e) => {
2967-
debug_eprintln!("{}", e);
2967+
log::error!("{}", e);
29682968
}
29692969
}
29702970
}
@@ -2974,7 +2974,7 @@ fn handle_user_message<T: UserEvent>(
29742974
windows.0.borrow_mut().insert(window_id, webview);
29752975
}
29762976
Err(e) => {
2977-
debug_eprintln!("{}", e);
2977+
log::error!("{}", e);
29782978
}
29792979
},
29802980
Message::CreateRawWindow(window_id, handler, sender) => {

core/tauri-utils/src/lib.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ use std::{
2222
use semver::Version;
2323
use serde::{Deserialize, Deserializer, Serialize, Serializer};
2424

25-
use log::warn;
26-
2725
pub mod acl;
2826
pub mod assets;
2927
pub mod config;
@@ -320,7 +318,7 @@ impl Default for Env {
320318
.unwrap_or(true);
321319

322320
if !is_temp {
323-
warn!("`APPDIR` or `APPIMAGE` environment variable found but this application was not detected as an AppImage; this might be a security issue.");
321+
log::warn!("`APPDIR` or `APPIMAGE` environment variable found but this application was not detected as an AppImage; this might be a security issue.");
324322
}
325323
}
326324
env
@@ -388,34 +386,6 @@ pub enum Error {
388386
NotAllowedToWalkDir(std::path::PathBuf),
389387
}
390388

391-
/// Suppresses the unused-variable warnings of the given inputs.
392-
///
393-
/// This does not move any values. Instead, it just suppresses the warning by taking a
394-
/// reference to the value.
395-
#[macro_export]
396-
macro_rules! consume_unused_variable {
397-
($($arg:expr),*) => {
398-
$(
399-
let _ = &$arg;
400-
)*
401-
()
402-
};
403-
}
404-
405-
/// Prints to the standard error, with a newline.
406-
///
407-
/// Equivalent to the [`eprintln!`] macro, except that it's only effective for debug builds.
408-
#[macro_export]
409-
macro_rules! debug_eprintln {
410-
() => ($crate::debug_eprintln!(""));
411-
($($arg:tt)*) => {
412-
#[cfg(debug_assertions)]
413-
eprintln!($($arg)*);
414-
#[cfg(not(debug_assertions))]
415-
$crate::consume_unused_variable!($($arg)*);
416-
};
417-
}
418-
419389
/// Reconstructs a path from its components using the platform separator then converts it to String and removes UNC prefixes on Windows if it exists.
420390
pub fn display_path<P: AsRef<Path>>(p: P) -> String {
421391
dunce::simplified(&p.as_ref().components().collect::<PathBuf>())

core/tauri/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ico = { version = "0.3.0", optional = true }
7373
http-range = { version = "0.1.5", optional = true }
7474
tracing = { version = "0.1", optional = true }
7575
heck = "0.4"
76+
log = "0.4"
7677

7778
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies]
7879
muda = { version = "0.11", default-features = false, features = [ "serde" ] }
@@ -96,9 +97,6 @@ window-vibrancy = "0.5"
9697
version = "0.52"
9798
features = [ "Win32_Foundation" ]
9899

99-
[target."cfg(any(target_os = \"android\", target_os = \"ios\"))".dependencies]
100-
log = "0.4"
101-
102100
[target."cfg(target_os = \"android\")".dependencies]
103101
jni = "0.21"
104102

core/tauri/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use tauri_runtime::{
4040
},
4141
RuntimeInitArgs,
4242
};
43-
use tauri_utils::{debug_eprintln, PackageInfo};
43+
use tauri_utils::PackageInfo;
4444

4545
use std::{
4646
borrow::Cow,
@@ -402,7 +402,7 @@ impl<R: Runtime> AppHandle<R> {
402402
/// Exits the app by triggering [`RunEvent::ExitRequested`] and [`RunEvent::Exit`].
403403
pub fn exit(&self, exit_code: i32) {
404404
if let Err(e) = self.runtime_handle.request_exit(exit_code) {
405-
debug_eprintln!("failed to exit: {}", e);
405+
log::error!("failed to exit: {}", e);
406406
self.cleanup_before_exit();
407407
std::process::exit(exit_code);
408408
}

core/tauri/src/manager/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use serde::Serialize;
1313
use url::Url;
1414

1515
use tauri_macros::default_runtime;
16-
use tauri_utils::debug_eprintln;
1716
use tauri_utils::{
1817
assets::{AssetKey, CspHash},
1918
config::{Csp, CspDirectiveSources},
@@ -67,7 +66,7 @@ fn set_csp<R: Runtime>(
6766
acc.style.push(hash.into());
6867
}
6968
_csp_hash => {
70-
debug_eprintln!("Unknown CspHash variant encountered: {:?}", _csp_hash);
69+
log::debug!("Unknown CspHash variant encountered: {:?}", _csp_hash);
7170
}
7271
}
7372

@@ -362,14 +361,14 @@ impl<R: Runtime> AppManager<R> {
362361
let asset_response = assets
363362
.get(&path.as_str().into())
364363
.or_else(|| {
365-
debug_eprintln!("Asset `{path}` not found; fallback to {path}.html");
364+
log::debug!("Asset `{path}` not found; fallback to {path}.html");
366365
let fallback = format!("{}.html", path.as_str()).into();
367366
let asset = assets.get(&fallback);
368367
asset_path = fallback;
369368
asset
370369
})
371370
.or_else(|| {
372-
debug_eprintln!(
371+
log::debug!(
373372
"Asset `{}` not found; fallback to {}/index.html",
374373
path,
375374
path
@@ -380,7 +379,7 @@ impl<R: Runtime> AppManager<R> {
380379
asset
381380
})
382381
.or_else(|| {
383-
debug_eprintln!("Asset `{}` not found; fallback to index.html", path);
382+
log::debug!("Asset `{}` not found; fallback to index.html", path);
384383
let fallback = AssetKey::from("index.html");
385384
let asset = assets.get(&fallback);
386385
asset_path = fallback;
@@ -412,7 +411,7 @@ impl<R: Runtime> AppManager<R> {
412411
})
413412
}
414413
Err(e) => {
415-
debug_eprintln!("{:?}", e); // TODO log::error!
414+
log::error!("{:?}", e);
416415
Err(Box::new(e))
417416
}
418417
}

core/tauri/src/protocol/asset.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{path::SafePathBuf, scope, webview::UriSchemeProtocolHandler};
66
use http::{header::*, status::StatusCode, Request, Response};
77
use http_range::HttpRange;
88
use std::{borrow::Cow, io::SeekFrom};
9-
use tauri_utils::debug_eprintln;
109
use tauri_utils::mime_type::MimeType;
1110
use tokio::fs::File;
1211
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
@@ -40,12 +39,12 @@ fn get_response(
4039
let mut resp = Response::builder().header("Access-Control-Allow-Origin", window_origin);
4140

4241
if let Err(e) = SafePathBuf::new(path.clone().into()) {
43-
debug_eprintln!("asset protocol path \"{}\" is not valid: {}", path, e);
42+
log::error!("asset protocol path \"{}\" is not valid: {}", path, e);
4443
return resp.status(403).body(Vec::new().into()).map_err(Into::into);
4544
}
4645

4746
if !scope.is_allowed(&path) {
48-
debug_eprintln!("asset protocol not configured to allow the path: {}", path);
47+
log::error!("asset protocol not configured to allow the path: {}", path);
4948
return resp.status(403).body(Vec::new().into()).map_err(Into::into);
5049
}
5150

core/tauri/src/protocol/tauri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn get_response<R: Runtime>(
146146
.body(response.body.to_vec().into())?
147147
}
148148
Err(e) => {
149-
tauri_utils::debug_eprintln!("Failed to request {}: {}", url.as_str(), e);
149+
log::error!("Failed to request {}: {}", url.as_str(), e);
150150
return Err(Box::new(e));
151151
}
152152
}

0 commit comments

Comments
 (0)