From 4ba885531da67fa5e64d9b0ed4e98b3e0a6dae0d Mon Sep 17 00:00:00 2001 From: koko Date: Tue, 24 Feb 2026 00:05:20 +0100 Subject: [PATCH] chore: move from print to tracing --- Cargo.lock | 4 ++ Cargo.toml | 60 +++++++++++----------- apps/browser/Cargo.toml | 2 +- apps/readme/Cargo.toml | 10 ++-- apps/readme/src/main.rs | 3 ++ packages/blitz-dom/src/document.rs | 3 +- packages/blitz-dom/src/events/ime.rs | 3 +- packages/blitz-dom/src/events/pointer.rs | 6 ++- packages/blitz-dom/src/layout/construct.rs | 10 ++-- packages/blitz-dom/src/layout/mod.rs | 9 ++-- packages/blitz-dom/src/layout/table.rs | 3 +- packages/blitz-dom/src/node/element.rs | 9 ++-- packages/blitz-dom/src/resolve.rs | 3 +- packages/blitz-html/Cargo.toml | 7 ++- packages/blitz-html/src/html_sink.rs | 3 +- packages/blitz-net/Cargo.toml | 4 +- packages/blitz-net/src/lib.rs | 39 ++++++++------ packages/blitz/Cargo.toml | 6 ++- packages/blitz/src/lib.rs | 3 +- packages/dioxus-native/Cargo.toml | 2 +- 20 files changed, 114 insertions(+), 75 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0f6596a4..068b9f9df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -809,6 +809,7 @@ dependencies = [ "blitz-shell", "blitz-traits", "tokio", + "tracing", "url", ] @@ -888,6 +889,7 @@ dependencies = [ "blitz-dom", "blitz-traits", "html5ever", + "tracing", "xml5ever", ] @@ -902,6 +904,7 @@ dependencies = [ "reqwest", "reqwest-middleware", "tokio", + "tracing", ] [[package]] @@ -5684,6 +5687,7 @@ dependencies = [ "pulldown-cmark", "reqwest", "tokio", + "tracing-subscriber", "url", "winit", ] diff --git a/Cargo.toml b/Cargo.toml index 1101793ce..31a8804a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,24 +1,24 @@ [workspace] members = [ - "packages/accesskit_xplat", - "packages/debug_timer", - "packages/blitz-traits", - "packages/blitz-dom", - "packages/blitz-html", - "packages/blitz-net", - "packages/blitz-paint", - "packages/blitz-shell", - "packages/blitz", - "packages/stylo_taffy", - "packages/dioxus-native", - "packages/dioxus-native-dom", - "apps/browser", - "apps/readme", - "apps/bump", - "wpt/runner", - "examples/counter", - "examples/todomvc", - "examples/wgpu_texture", + "packages/accesskit_xplat", + "packages/debug_timer", + "packages/blitz-traits", + "packages/blitz-dom", + "packages/blitz-html", + "packages/blitz-net", + "packages/blitz-paint", + "packages/blitz-shell", + "packages/blitz", + "packages/stylo_taffy", + "packages/dioxus-native", + "packages/dioxus-native-dom", + "apps/browser", + "apps/readme", + "apps/bump", + "wpt/runner", + "examples/counter", + "examples/todomvc", + "examples/wgpu_texture", ] exclude = ["sites"] resolver = "2" @@ -88,13 +88,13 @@ dioxus-core-macro = { version = "0.7.3" } # Taffy taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "25759dad44d8350743a4e866fee54962f996895a", default-features = false, features = [ - "std", - "flexbox", - "grid", - "block_layout", - "content_size", - "calc", - "detailed_layout_info", + "std", + "flexbox", + "grid", + "block_layout", + "content_size", + "calc", + "detailed_layout_info", ] } # AnyRender @@ -112,10 +112,10 @@ linebender_resource_handle = "0.1" peniko = "0.6.0" kurbo = "0.13" parley = { git = "https://github.com/linebender/parley", rev = "37aa8ab7103e9da89eea22899902016ce20739f2", default-features = false, features = [ - "std", + "std", ] } skrifa = { version = "0.40", default-features = false, features = [ - "std", + "std", ] } # Should match parley version wgpu = "27" softbuffer = "0.4" @@ -123,8 +123,8 @@ pixels = "0.15" vello = { version = "0.6", features = ["wgpu"] } vello_encoding = { version = "0.6", default-features = false } vello_cpu = { version = "0.0.3", default-features = false, features = [ - "std", - "text", + "std", + "text", ] } usvg = "0.46" diff --git a/apps/browser/Cargo.toml b/apps/browser/Cargo.toml index 090c6ead4..813c03bee 100644 --- a/apps/browser/Cargo.toml +++ b/apps/browser/Cargo.toml @@ -26,7 +26,7 @@ cache = ["blitz-net/cache"] cookies = ["blitz-net/cookies"] avif = ["image/avif"] webp = ["image/webp"] -tracing = ["dioxus-native/tracing", "dep:tracing-subscriber"] +tracing = ["dioxus-native/tracing", "blitz-html/tracing", "blitz-net/tracing", "dep:tracing-subscriber"] hot-reload = ["dioxus-native/hot-reload"] accessibility = ["dioxus-native/accessibility"] mimalloc = ["dep:mimalloc"] diff --git a/apps/readme/Cargo.toml b/apps/readme/Cargo.toml index 60dbb7260..afd268810 100644 --- a/apps/readme/Cargo.toml +++ b/apps/readme/Cargo.toml @@ -7,7 +7,7 @@ rust-version.workspace = true publish = false [features] -default = ["gpu", "comrak", "floats"] +default = ["gpu", "comrak", "floats", "tracing"] # Renderers gpu = ["dep:anyrender_vello"] @@ -34,14 +34,15 @@ log_frame_times = [ ] log_phase_times = ["blitz-dom/log_phase_times"] incremental = ["blitz-dom/incremental"] +tracing = ["dep:tracing-subscriber", "blitz-shell/tracing", "blitz-net/tracing", "blitz-html/tracing"] [dependencies] blitz-traits = { workspace = true } blitz-dom = { workspace = true, features = ["default", "parallel-construct"] } blitz-html = { workspace = true } blitz-paint = { workspace = true, features = ["default"] } -blitz-net = { workspace = true, features = ["cookies", "debug_log"] } -blitz-shell = { workspace = true, features = ["tracing", "default"] } +blitz-net = { workspace = true, features = ["cookies"] } +blitz-shell = { workspace = true, features = ["default"] } anyrender_vello = { workspace = true, optional = true } anyrender_skia = { workspace = true, optional = true } anyrender_vello_cpu = { workspace = true, features = ["multithreading"], optional = true } @@ -54,4 +55,5 @@ winit = { workspace = true } comrak = { version = "0.50", default-features = false, optional = true } pulldown-cmark = { version = "0.13", default-features = false, features = ["html"], optional = true } image = { workspace = true, default-features = false, optional = true } -notify = "8.0.0" \ No newline at end of file +notify = "8.0.0" +tracing-subscriber = { workspace = true, optional = true } diff --git a/apps/readme/src/main.rs b/apps/readme/src/main.rs index b1742621a..43103f20b 100644 --- a/apps/readme/src/main.rs +++ b/apps/readme/src/main.rs @@ -58,6 +58,9 @@ impl NavigationProvider for ReadmeNavigationProvider { } fn main() { + #[cfg(feature = "tracing")] + tracing_subscriber::fmt::init(); + let raw_url = std::env::args().nth(1).unwrap_or_else(|| { let cwd = current_dir().unwrap(); format!("{}", cwd.display()) diff --git a/packages/blitz-dom/src/document.rs b/packages/blitz-dom/src/document.rs index 24ea67dd2..8e4730418 100644 --- a/packages/blitz-dom/src/document.rs +++ b/packages/blitz-dom/src/document.rs @@ -1088,7 +1088,8 @@ impl BaseDocument { .first_element_child() .is_none() { - println!("No DOM - not resolving"); + #[cfg(feature = "tracing")] + tracing::warn!("No DOM - not resolving hit test"); return None; } diff --git a/packages/blitz-dom/src/events/ime.rs b/packages/blitz-dom/src/events/ime.rs index ad629915a..8951d2f22 100644 --- a/packages/blitz-dom/src/events/ime.rs +++ b/packages/blitz-dom/src/events/ime.rs @@ -50,7 +50,8 @@ pub(crate) fn handle_ime_event( // TODO } } - println!("Sent ime event to {node_id}"); + #[cfg(feature = "tracing")] + tracing::debug!(node_id, "Sent ime event"); } } } diff --git a/packages/blitz-dom/src/events/pointer.rs b/packages/blitz-dom/src/events/pointer.rs index 8beb78f77..a2e1028d0 100644 --- a/packages/blitz-dom/src/events/pointer.rs +++ b/packages/blitz-dom/src/events/pointer.rs @@ -520,11 +520,13 @@ pub(crate) fn handle_click( doc.id(), )); } else { - println!("{href} is not parseable as a url. : {:?}", *doc.url) + #[cfg(feature = "tracing")] + tracing::warn!("{href} is not parseable as a url. : {:?}", *doc.url); } break 'matched true; } else { - println!("Clicked link without href: {:?}", el.attrs()); + #[cfg(feature = "tracing")] + tracing::info!("Clicked link without href: {:?}", el.attrs()); } } local_name!("input") diff --git a/packages/blitz-dom/src/layout/construct.rs b/packages/blitz-dom/src/layout/construct.rs index b01a17241..9441d8ce6 100644 --- a/packages/blitz-dom/src/layout/construct.rs +++ b/packages/blitz-dom/src/layout/construct.rs @@ -150,9 +150,13 @@ pub(crate) fn collect_layout_children( .special_data = SpecialElementData::Image(Box::new(svg.into())); } Err(err) => { - println!("{container_node_id} SVG parse failed"); - println!("{outer_html}"); - dbg!(err); + #[cfg(feature = "tracing")] + tracing::warn!( + node_id = container_node_id, + html = outer_html, + error = ?err, + "SVG parse failed", + ); } }; return; diff --git a/packages/blitz-dom/src/layout/mod.rs b/packages/blitz-dom/src/layout/mod.rs index 10933eebb..7a6fb0781 100644 --- a/packages/blitz-dom/src/layout/mod.rs +++ b/packages/blitz-dom/src/layout/mod.rs @@ -72,11 +72,12 @@ impl BaseDocument { NodeData::Text(data) => { // With the new "inline context" architecture all text nodes should be wrapped in an "inline layout context" // and should therefore never be measured individually. - println!( - "ERROR: Tried to lay out text node individually ({})", - usize::from(node_id) + #[cfg(feature = "tracing")] + tracing::error!( + node_id = usize::from(node_id), + data = ?data, + "Tried to lay out text node individually", ); - dbg!(data); taffy::LayoutOutput::HIDDEN // unreachable!(); diff --git a/packages/blitz-dom/src/layout/table.rs b/packages/blitz-dom/src/layout/table.rs index 7b2230ce3..7ed99c69d 100644 --- a/packages/blitz-dom/src/layout/table.rs +++ b/packages/blitz-dom/src/layout/table.rs @@ -178,7 +178,8 @@ pub(crate) fn collect_table_cells( } let Some(display) = node.primary_styles().map(|s| s.clone_display()) else { - println!("Ignoring table descendent because it has no styles"); + #[cfg(feature = "tracing")] + tracing::info!("Ignoring table descendent because it has no styles"); return; }; diff --git a/packages/blitz-dom/src/node/element.rs b/packages/blitz-dom/src/node/element.rs index e24ba68f3..7ff28c830 100644 --- a/packages/blitz-dom/src/node/element.rs +++ b/packages/blitz-dom/src/node/element.rs @@ -341,7 +341,8 @@ impl ElementData { ); let Ok(property_id) = PropertyId::parse(name, &context) else { - eprintln!("Warning: unsupported property {name}"); + #[cfg(feature = "tracing")] + tracing::warn!(property = name, "Unsupported property"); return false; }; let mut source_property_declaration = SourcePropertyDeclaration::default(); @@ -353,7 +354,8 @@ impl ElementData { &context, &mut parser, ) else { - eprintln!("Warning: invalid property value for {name}: {value}"); + #[cfg(feature = "tracing")] + tracing::warn!(property = name, value, "Invalid property value"); return false; }; @@ -386,7 +388,8 @@ impl ElementData { None, ); let Ok(property_id) = PropertyId::parse(name, &context) else { - eprintln!("Warning: unsupported property {name}"); + #[cfg(feature = "tracing")] + tracing::warn!(property = name, "Unsupported property"); return false; }; diff --git a/packages/blitz-dom/src/resolve.rs b/packages/blitz-dom/src/resolve.rs index 759b4f2df..6bc6a2a9b 100644 --- a/packages/blitz-dom/src/resolve.rs +++ b/packages/blitz-dom/src/resolve.rs @@ -43,7 +43,8 @@ impl BaseDocument { .first_element_child() .is_none() { - println!("No DOM - not resolving"); + #[cfg(feature = "tracing")] + tracing::warn!("No DOM - not resolving"); return; } diff --git a/packages/blitz-html/Cargo.toml b/packages/blitz-html/Cargo.toml index 7556cbf53..d3102abd1 100644 --- a/packages/blitz-html/Cargo.toml +++ b/packages/blitz-html/Cargo.toml @@ -10,6 +10,9 @@ categories.workspace = true edition.workspace = true rust-version.workspace = true +[features] +tracing = ["dep:tracing", "blitz-dom/tracing"] + [dependencies] # Blitz dependencies blitz-dom = { workspace = true } @@ -17,4 +20,6 @@ blitz-traits = { workspace = true } # Servo dependencies html5ever = { workspace = true } -xml5ever = { workspace = true } \ No newline at end of file +xml5ever = { workspace = true } + +tracing = { workspace = true, optional = true } diff --git a/packages/blitz-html/src/html_sink.rs b/packages/blitz-html/src/html_sink.rs index 321b140b6..1aacc8151 100644 --- a/packages/blitz-html/src/html_sink.rs +++ b/packages/blitz-html/src/html_sink.rs @@ -146,7 +146,8 @@ impl<'m, 'doc> TreeSink for DocumentHtmlParser<'m, 'doc> { fn finish(self) -> Self::Output { for error in self.errors.borrow().iter() { - println!("ERROR: {error}"); + #[cfg(feature = "tracing")] + tracing::error!("{error}"); } } diff --git a/packages/blitz-net/Cargo.toml b/packages/blitz-net/Cargo.toml index 30d0e6c86..e65e05fe1 100644 --- a/packages/blitz-net/Cargo.toml +++ b/packages/blitz-net/Cargo.toml @@ -15,7 +15,7 @@ http2 = ["reqwest/http2"] cookies = ["reqwest/cookies"] multipart = ["reqwest/multipart", "reqwest/stream"] cache = ["dep:reqwest-middleware", "dep:http-cache-reqwest", "dep:directories"] -debug_log = [] +tracing = ["dep:tracing"] [dependencies] # Blitz dependencies @@ -30,3 +30,5 @@ data-url = { workspace = true } reqwest-middleware = { workspace = true, optional = true } http-cache-reqwest = { workspace = true, optional = true, features = ["manager-cacache"] } directories = { version = "6.0.0", optional = true } + +tracing = { workspace = true, optional = true } diff --git a/packages/blitz-net/src/lib.rs b/packages/blitz-net/src/lib.rs index 764782a97..70a270e6b 100644 --- a/packages/blitz-net/src/lib.rs +++ b/packages/blitz-net/src/lib.rs @@ -30,7 +30,8 @@ fn get_cache_path() -> std::path::PathBuf { .expect("Failed to find cache directory") .cache_dir() .to_owned(); - println!("Using cache dir {}", path.display()); + #[cfg(feature = "tracing")] + tracing::info!(path = ?path.display(), "Using cache dir"); path } @@ -109,18 +110,20 @@ impl Provider { request: Request, callback: Box) + Send + Sync + 'static>, ) { - #[cfg(feature = "debug_log")] + #[cfg(feature = "tracing")] let url = request.url.to_string(); let client = self.client.clone(); self.rt.spawn(async move { let result = Self::fetch_inner(client, request).await; - #[cfg(feature = "debug_log")] + #[cfg(feature = "tracing")] if let Err(e) = &result { - eprintln!("Error fetching {url}: {e:?}"); + #[cfg(feature = "tracing")] + tracing::error!(url = url.as_str(), error = ?e, "Fetching"); } else { - println!("Success {url}"); + #[cfg(feature = "tracing")] + tracing::info!(url = url.as_str(), "Success fetching"); } callback(result); @@ -128,17 +131,19 @@ impl Provider { } pub async fn fetch_async(&self, request: Request) -> Result<(String, Bytes), ProviderError> { - #[cfg(feature = "debug_log")] + #[cfg(feature = "tracing")] let url = request.url.to_string(); let client = self.client.clone(); let result = Self::fetch_inner(client, request).await; - #[cfg(feature = "debug_log")] + #[cfg(feature = "tracing")] if let Err(e) = &result { - eprintln!("Error fetching {url}: {e:?}"); + #[cfg(feature = "tracing")] + tracing::error!(url = url.as_str(), error = ?e, "Fetching"); } else { - println!("Success {url}"); + #[cfg(feature = "tracing")] + tracing::info!(url = url.as_str(), "Success fetching"); } result @@ -149,12 +154,12 @@ impl NetProvider for Provider { fn fetch(&self, doc_id: usize, mut request: Request, handler: Box) { let client = self.client.clone(); - #[cfg(feature = "debug_log")] - println!("Fetching {}", &request.url); + #[cfg(feature = "tracing")] + tracing::info!(url = request.url.as_str(), "Fetching"); let waker = self.waker.clone(); self.rt.spawn(async move { - #[cfg(feature = "debug_log")] + #[cfg(feature = "tracing")] let url = request.url.to_string(); let signal = request.signal.take(); @@ -174,13 +179,13 @@ impl NetProvider for Provider { match result { Ok((response_url, bytes)) => { handler.bytes(response_url, bytes); - #[cfg(feature = "debug_log")] - println!("Success {url}"); + #[cfg(feature = "tracing")] + tracing::info!(url = url.as_str(), "Success fetching"); } Err(e) => { - #[cfg(feature = "debug_log")] - eprintln!("Error fetching {url}: {e:?}"); - #[cfg(not(feature = "debug_log"))] + #[cfg(feature = "tracing")] + tracing::error!(url = url.as_str(), error = ?e, "Error fetching"); + #[cfg(not(feature = "tracing"))] let _ = e; } }; diff --git a/packages/blitz/Cargo.toml b/packages/blitz/Cargo.toml index 0be24bedd..415db3cec 100644 --- a/packages/blitz/Cargo.toml +++ b/packages/blitz/Cargo.toml @@ -11,10 +11,10 @@ edition.workspace = true rust-version.workspace = true [features] -default = ["net", "accessibility"] +default = ["net", "accessibility", "tracing"] net = ["dep:tokio", "dep:url", "dep:blitz-net"] accessibility = ["blitz-shell/accessibility"] -tracing = ["blitz-shell/tracing"] +tracing = ["dep:tracing", "blitz-shell/tracing", "blitz-html/tracing", "blitz-net/tracing"] [dependencies] # Blitz dependencies @@ -30,6 +30,8 @@ blitz-net = { workspace = true, optional = true } url = { workspace = true, features = ["serde"], optional = true } tokio = { workspace = true, features = ["rt-multi-thread"], optional = true } +tracing = { workspace = true, optional = true } + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/packages/blitz/src/lib.rs b/packages/blitz/src/lib.rs index 0f89192d5..58e2cf231 100644 --- a/packages/blitz/src/lib.rs +++ b/packages/blitz/src/lib.rs @@ -44,7 +44,8 @@ pub use blitz_traits as traits; #[cfg(feature = "net")] pub fn launch_url(url: &str) { // Assert that url is valid - println!("{url}"); + #[cfg(feature = "tracing")] + tracing::info!("Launching {url}"); let url = url.to_owned(); let url = url::Url::parse(&url).expect("Invalid url"); diff --git a/packages/dioxus-native/Cargo.toml b/packages/dioxus-native/Cargo.toml index 91b413412..3173be8f1 100644 --- a/packages/dioxus-native/Cargo.toml +++ b/packages/dioxus-native/Cargo.toml @@ -53,7 +53,7 @@ log-frame-times = [ "anyrender_vello_hybrid?/log_frame_times", "anyrender_skia?/log_frame_times", ] -tracing = ["dep:tracing", "dioxus-native-dom/tracing", "blitz-shell/tracing", "blitz-dom/tracing"] +tracing = ["dep:tracing", "dioxus-native-dom/tracing", "blitz-shell/tracing", "blitz-dom/tracing", "blitz-html/tracing", "blitz-net/tracing"] [dependencies] # Blitz dependencies